This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Stefan.Bucur
Recipients Stefan.Bucur
Date 2013-04-03.10:45:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1364985905.97.0.615690774313.issue17624@psf.upfronthosting.co.za>
In-reply-to
Content
When calling urllib.urlopen with a string containing the NULL ('\x00') character, a TypeError exception is thrown, as in the following example:

urllib.urlopen('\x00\x00\x00')

[...]
  File "/home/bucur/onion/python-bin/lib/python2.7/urllib.py", line 86, in urlopen
    return opener.open(url)
  File "/home/bucur/onion/python-bin/lib/python2.7/urllib.py", line 207, in open
    return getattr(self, name)(url)
  File "/home/bucur/onion/python-bin/lib/python2.7/urllib.py", line 462, in open_file
    return self.open_local_file(url)
  File "/home/bucur/onion/python-bin/lib/python2.7/urllib.py", line 474, in open_local_file
    stats = os.stat(localname)
TypeError: must be encoded string without NULL bytes, not str


This exception is confusing, since apparently the right type (a string) is passed to the function.  Since this behavior cannot change, it would be good to mention this exception in the function documentation.

I can imagine code that composes a URL based on user-supplied input and passes it to urlopen crashing if it doesn't properly sanitize the URL and/or doesn't catch TypeError.
History
Date User Action Args
2013-04-03 10:45:06Stefan.Bucursetrecipients: + Stefan.Bucur
2013-04-03 10:45:05Stefan.Bucursetmessageid: <1364985905.97.0.615690774313.issue17624@psf.upfronthosting.co.za>
2013-04-03 10:45:05Stefan.Bucurlinkissue17624 messages
2013-04-03 10:45:05Stefan.Bucurcreate