Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with Python < 2.6.5 #110

Closed
yan12125 opened this issue Jan 16, 2016 · 5 comments
Closed

Not working with Python < 2.6.5 #110

yan12125 opened this issue Jan 16, 2016 · 5 comments

Comments

@yan12125
Copy link
Contributor

With Python 2.6.4 and the following code snippet:

import requests
from cachecontrol import CacheControl

sess = requests.session()
cached_sess = CacheControl(sess)

response = cached_sess.get('http://example.com')
response = cached_sess.get('http://example.com')

The following error occurs:

$ python test_cache.py
Traceback (most recent call last):
  File "test_cache.py", line 10, in <module>
    response = cached_sess.get('http://example.com')
  File "/home/yen/pyenv/lib/python2.6/site-packages/requests/sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "/home/yen/pyenv/lib/python2.6/site-packages/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/yen/pyenv/lib/python2.6/site-packages/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/home/yen/pyenv/lib/python2.6/site-packages/cachecontrol/adapter.py", line 36, in send
    cached_response = self.controller.cached_request(request)
  File "/home/yen/pyenv/lib/python2.6/site-packages/cachecontrol/controller.py", line 102, in cached_request
    resp = self.serializer.loads(request, self.cache.get(cache_url))
  File "/home/yen/pyenv/lib/python2.6/site-packages/cachecontrol/serialize.py", line 108, in loads
    return getattr(self, "_loads_v{0}".format(ver))(request, data)
  File "/home/yen/pyenv/lib/python2.6/site-packages/cachecontrol/serialize.py", line 184, in _loads_v2
    return self.prepare_response(request, cached)
  File "/home/yen/pyenv/lib/python2.6/site-packages/cachecontrol/serialize.py", line 145, in prepare_response
    **cached["response"]
TypeError: __init__() keywords must be strings

Related: pypa/pip#3074

@ionrock
Copy link
Contributor

ionrock commented Mar 24, 2016

@yan12125 I'd like to try and fix this, but I don't have a good way to install <2.6.5. pyenv only goes down to 2.6.6. If you have suggestions, please let me know!

@yan12125
Copy link
Contributor Author

If you're using Arch Linux, this PKGBUILD should work: https://github.com/yan12125/aur/tree/master/python264.

@sigmavirus24
Copy link
Contributor

@ionrock I suspect this is something that was broken in Python versions prior to 2.6.5 as it was fixed and documented by https://bugs.python.org/issue4978. The release notes for 2.6.5 document as that being fixed in 2.6.5rc1. Further versions 2.6.6 through 2.6.9 all contain various very important security fixes. I think you can support Python 2.6 for versions of 2.6 that aren't terribly broken and insecure. You might just want to say that the only version of 2.6 you want to support is 2.6.9 (or 2.6.6, 2.6.7, and 2.6.9) and that would be completely valid.

@ionrock
Copy link
Contributor

ionrock commented Mar 24, 2016

@sigmavirus24 Ah hah! Thanks!

So, I'm happy to support 2.6 versions supported by pyenv b/c I can test those, which means >=2.6.6.

@yan12125 I'm going to go ahead and close this out. That said, if you find a fix and can submit a patch, I'm happy to review it.

@ionrock ionrock closed this as completed Mar 24, 2016
@sigmavirus24
Copy link
Contributor

@ionrock the fix would be to take that dictionary stored in cached["repository"] and do something like:

if (2, 6, 0) <= sys.version_info < (2, 6, 5):
    kwargs = dict((k.encode('utf-8'), v) for (k, v) in cached["response"].items())
else:
    kwargs = cached["response"]

And then splat the kwargs but that's quite a horrible hack to support (and facilitate) usage of versions of Python that are:

  • no longer receiving security fixes
  • terribly insecure and susceptible to multiple attacks
  • no longer something you can easily proactively test with

While that fix is easy enough, I don't think it's a net benefit to a great deal of people.


For code golf purposes you could also do

kwargs = cached["response"]
if (2, 6, 0) <= sys.version_info < (2, 6, 5):
    kwargs = dict((k.encode('utf-8'), v) for (k, v) in kwargs.items())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants