[Python-bugs-list] [ python-Bugs-225217 ] urllib2.py and proxies (Python 2.0)

nobody nobody@sourceforge.net
Tue, 06 Mar 2001 03:24:11 -0800


Bugs #225217, was updated on 2000-12-09 22:12
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=225217&group_id=5470

Category: Python Library
Group: None
Status: Open
Priority: 5
Submitted By: The Written Word (china)
Assigned to: Jeremy Hylton
Summary: urllib2.py and proxies (Python 2.0)

Initial Comment:
Consider the following program:

  import os, sys, urllib2
  from urllib2 import urlopen
        
  os.environ['http_proxy'] = 'http://[HOST]:5865'
   
  authinfo = urllib2.HTTPBasicAuthHandler ()
  authinfo.add_password ('[REALM]', 'http://[URL]', '[login]', 
  '[password]')
        
  opener = urllib2.build_opener (authinfo)
  urllib2.install_opener (opener)

  url = urlopen ('http://[URL]/')
  print url.info ()
  url.close ()

Urllib2.py does not work if we wish to do BASIC authentication to a URL through a proxy. Chances are it also will not work if the proxy requires BASIC authentication too and the URL requires BASIC authentication. Here's the error I receive (Solaris 7/SPARC but platform does not matter):

    File "/tmp/a.py", line 15, in ?                          
      url = urlopen ('http://updates.thewrittenword.com/')
    File "/opt/TWWfsw/pkgutils12/lib/python20/lib/python2.0/urllib2.py",
  line 137, in urlopen
      return _opener.open(url, data)
    File "/opt/TWWfsw/pkgutils12/lib/python20/lib/python2.0/urllib2.py",
  line 325, in open
      '_open', req)
    File "/opt/TWWfsw/pkgutils12/lib/python20/lib/python2.0/urllib2.py",
  line 304, in _call_chain
      result = func(*args)
    File "/opt/TWWfsw/pkgutils12/lib/python20/lib/python2.0/urllib2.py",
  line 764, in http_open
      return self.parent.error('http', req, fp, code, msg, hdrs)
    File "/opt/TWWfsw/pkgutils12/lib/python20/lib/python2.0/urllib2.py",
  line 351, in error
      return self._call_chain(*args)
    File "/opt/TWWfsw/pkgutils12/lib/python20/lib/python2.0/urllib2.py",
  line 304, in _call_chain
      result = func(*args)
    File "/opt/TWWfsw/pkgutils12/lib/python20/lib/python2.0/urllib2.py",
  line 430, in http_error_default
      raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
  urllib2.HTTPError: HTTP Error 401: Authorization Required


----------------------------------------------------------------------

Comment By: Nobody/Anonymous
Date: 2001-03-06 03:24

Message:
Logged In: NO 

alike for $ftp_proxy:
  File "/usr/local/lib/python2.0/urllib.py", line 61, in
urlopen
    return _urlopener.open(url)
  File "/usr/local/lib/python2.0/urllib.py", line 166, in
open
    return getattr(self, name)(url)
  File "/usr/local/lib/python2.0/urllib.py", line 416, in
open_ftp
    host, path = splithost(url)
  File "/usr/local/lib/python2.0/urllib.py", line 885, in
splithost
    match = _hostprog.match(url)
TypeError: expected string or buffer


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=225217&group_id=5470