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

SimpleCookie throws AttributeError: 'str' object has no attribute 'items' #203

Open
serac opened this issue Mar 24, 2016 · 1 comment
Open

Comments

@serac
Copy link

serac commented Mar 24, 2016

Interactive session demonstrating problem:

marvin@eiger:~$ python
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from future.backports.http.cookies import SimpleCookie
>>> kaka='JSESSIONID=189xm7lb936kjxt7bbwxqf1lb'
>>> cookie_object = SimpleCookie(kaka)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/future-0.15.2-py2.7.egg/future/backports/http/cookies.py", line 492, in __init__
    self.load(input)
  File "/usr/local/lib/python2.7/site-packages/future-0.15.2-py2.7.egg/future/backports/http/cookies.py", line 545, in load
    for key, value in rawdata.items():

The error is caused by the following isinstance check:

    if isinstance(rawdata, str):
        self.__parse_string(rawdata)
    else:
        # self.update() wouldn't call our custom __setitem__
        for key, value in rawdata.items():
            self[key] = value
    return

I have verified that replacing str with basestring fixes the problem, but I am totally at a loss as to why.

@djdutcher
Copy link

The problem seems to be that str has been replaced:

from future.builtins import chr, dict, int, str

Therefore in Python 2 a literal string won't be of type str:

Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
[GCC 5.3.1 20160413] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 'foo'
>>> isinstance(a, str)
True
>>> from future.builtins import str
>>> isinstance(a, str)
False
>>> b = 'bar'
>>> isinstance(b, str)
False

Maybe the code will need to check if it is PY2 and then test for an instance of basestring.

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

No branches or pull requests

3 participants