2

So I have a website which has a cookie with an integer in it, causing Requests to fail:

import requests
r = requests.get('http://www.c1000.nl/kies-uw-winkel.aspx')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/srv/www/li/venv/local/lib/python2.7/site-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/srv/www/li/venv/local/lib/python2.7/site-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/srv/www/li/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 361, in request
    resp = self.send(prep, **send_kwargs)
  File "/srv/www/li/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 464, in send
    r = adapter.send(request, **kwargs)
  File "/srv/www/li/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 369, in send
    r = self.build_response(request, resp)
  File "/srv/www/li/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 179, in build_response
    extract_cookies_to_jar(response.cookies, req, resp)
  File "/srv/www/li/venv/local/lib/python2.7/site-packages/requests/cookies.py", line 117, in extract_cookies_to_jar
    jar.extract_cookies(res, req)
  File "/usr/lib/python2.7/cookielib.py", line 1645, in extract_cookies
    self.set_cookie(cookie)
  File "/srv/www/li/venv/local/lib/python2.7/site-packages/requests/cookies.py", line 270, in set_cookie
    if cookie.value.startswith('"') and cookie.value.endswith('"'):
AttributeError: 'int' object has no attribute 'startswith'

Is this a bug in Requests? (i.e. shouldn't it be able to handle integers?) How can I avoid it? Is there a thing in a get request for avoid cookies?

System info:

  • Ubuntu 12.04LTS 64bit
  • Python 2.7.3
  • Request 2.0.1

2 Answers 2

1

This is a known bug, tracked by this GitHub issue. It will be fixed in the next release of Requests.

1
  • The root cause was a Python library bug: issue 23138. value shouldn't be an integer.
    – chfoo
    Mar 25, 2015 at 20:15
0

To handle cookies you should use a session that stores cookies between requests:

s = requests.Session()
r = s.get('http://www.c1000.nl/kies-uw-winkel.aspx',timeout=20)

This should do the trick. Im not sure why your code sample throws this exception though.. just a quick workaround.

1
  • Hi, it still throws the same error. It's not the problem of saving the cookie between requests but the fact that the cookie has an integer i think. Doesn't it create the same error for you? (i'll add some info about the versions)
    – Carst
    Dec 2, 2013 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.