python-hyper / hyper

HTTP/2 for Python.
http://hyper.rtfd.org/en/latest/
MIT License
1.05k stars 191 forks source link

basestring erroneously ignores unicode in Python2.7 #432

Open imankulov opened 4 years ago

imankulov commented 4 years ago

Documenting it for those poor souls who are still stuck with hyper under Python2.7.

Passing a Unicode object (not an "str") in Python2.7 to a hyper.tls.init_context as a cert argument raises an exception IOError: [Errno 21] Is a directory.

This happens because "basestring" is erroneously set to (str, str) here:

https://github.com/python-hyper/hyper/blob/18b629b8487169870235fe13387e2ae03c178b9f/hyper/tls.py#L123-L127

Note that because of the assignment to the basestring on line 127, an attempt to dereference the object before will always raise NameError, because the interpreter will consider basestring as a local variable. The behavior is explained in the Python FAQ, and the solution is to declare basestring as global explicitly.