New submission from Dmitry Jemerov <intelliy...@gmail.com>:

I'm trying to download a file from a site using HTTP authentication. I'm 
subclassing FancyURLOpener, returning my credentials from the 
prompt_user_passwd() method, and using opener.retrieve() to download the file. 
I get the following error:

  File "C:/JetBrains/IDEA/build/eap/downandup.py", line 36, in download
    opener.retrieve(url, os.path.join(target_path, name))
  File "C:\Python31\lib\urllib\request.py", line 1467, in retrieve
    fp = self.open(url, data)
  File "C:\Python31\lib\urllib\request.py", line 1435, in open
    return getattr(self, name)(url)
  File "C:\Python31\lib\urllib\request.py", line 1609, in open_http
    return self._open_generic_http(http.client.HTTPConnection, url, data)
  File "C:\Python31\lib\urllib\request.py", line 1605, in _open_generic_http
    response.status, response.reason, response.msg, data)
  File "C:\Python31\lib\urllib\request.py", line 1621, in http_error
    result = method(url, fp, errcode, errmsg, headers)
  File "C:\Python31\lib\urllib\request.py", line 1859, in http_error_401
    return getattr(self,name)(url, realm)
  File "C:\Python31\lib\urllib\request.py", line 1931, in retry_http_basic_auth
    return self.open(newurl)
  File "C:\Python31\lib\urllib\request.py", line 1435, in open
    return getattr(self, name)(url)
  File "C:\Python31\lib\urllib\request.py", line 1609, in open_http
    return self._open_generic_http(http.client.HTTPConnection, url, data)
  File "C:\Python31\lib\urllib\request.py", line 1571, in _open_generic_http
    auth = base64.b64encode(user_passwd).strip()
  File "C:\Python31\lib\base64.py", line 56, in b64encode
    raise TypeError("expected bytes, not %s" % s.__class__.__name__)
TypeError: expected bytes, not str

The problem happens because _open_generic_http extracts the user password from 
the string URL, and passes the string to the b64encode method, which only 
accepts bytes and not strings. The problem happens with Python 3.1.1 for me, 
but as far as I can see it's still not fixed in the py3k branch as of now.

----------
components: Library (Lib)
messages: 100938
nosy: Dmitry.Jemerov
severity: normal
status: open
title: TypeError in urllib when trying to use HTTP authentication
versions: Python 3.1

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8123>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to