How do I use proxies with httplib?

befletch at my-dejanews.com befletch at my-dejanews.com
Wed Apr 21 20:39:48 EDT 1999


In article <099101be8c3f$cb6206e0$f29b12c2 at pythonware.com>,
  "Fredrik Lundh" <fredrik at pythonware.com> wrote:
> <befletch at my-dejanews.com> wrote:
> > I want to use httplib through a proxy server and I can't seem to get
> > it to work.
[...]
> you might be able to use urllib instead:
[...]

When I first looked at this I thought it wouldn't do the trick either,
since I wanted to use the HTTP POST protocol.  On further inspection
I see that urllib has that covered.  So I tried it out, only to run up
against a problem that I want to blame on urllib; it claims to not
recognize the http url type:

Python 1.5.1 (#0, Nov 18 1998, 12:17:58) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import urllib
>>> connection=urllib.urlopen('http://www.yahoo.com')

Traceback (innermost last):  File "<stdin>", line 1, in ?  File "C:\PROGRAM
FILES\HOMERUN\lib\python1.5\urllib.py", line 59, in urlopen  return
_urlopener.open(url)  File "C:\PROGRAM
FILES\HOMERUN\lib\python1.5\urllib.py", line 155, in open  return
self.open_unknown(fullurl)  File "C:\PROGRAM
FILES\HOMERUN\lib\python1.5\urllib.py", line 169, in open_unk nown  raise
IOError, ('url error', 'unknown url type', type) IOError: ('url error',
'unknown url type', 'http')

>>>

As a test, I hacked urllib by forcing it to think all url's are http
url's, like so:

#       name = 'open_' + type
        name = 'open_http'

This gets past the url type only to fail on the urllib line:

        if not host: raise IOError, ('http error', 'no host given')

Hacking in a host doesn't help much either.  Is there something wrong
with my proxy 'set' command?  (This is under W95)

SET http_proxy="100.287.14.130:80"

Thanks again,
- Bruce

(emailed & posted)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




More information about the Python-list mailing list