Proxy Authentication??
Matthias
matthias_w at my-deja.com
Mon Aug 21 04:21:10 EDT 2000
In article <slrn8pvrfi.49e.jepler.lnk at potty.housenet>,
jepler.lnk at lnk.ispi.net (jepler epler) wrote:
> On Sun, 20 Aug 2000 21:37:11 +1000, Steven Adams
> <adams_s at lab.eng.usyd.edu.au> wrote:
> >Hi all,
> >
> >does anyone know how to get a python script to deal with proxy
servers that
> >require authentication (username,password)?
>
> Sorry to followup a second time, but here is the code I was thinking
of.
> Best of luck!
>
> >From: jepler at inetnebr.com (Jeff Epler)
> Subject: urllib.py patch: proxy authentication
> Date: 27 Jan 2000 00:00:00 GMT
> Message-ID: <slrn88vbmb.pl8.jepler at craie.inetnebr.com>
> X-NNTP-Posting-Host: craie.housenet
> X-Trace: news2.randori.com 948940498 206.131.194.26 (Wed, 26 Jan 2000
18:34:58
> PST)
> Newsgroups: comp.lang.python
>
> The following patch adds support for proxies like
> http_proxy=http://USER:PASS@host:port/
> which would formerly confuse the urllib into giving a traceback about
a
> non-numeric port number. (the PASS at host:port portion)
>
> This patch is probably not ready for inclusion as-is, because the CVS
> version of python has a modified urllib that is too far distant for
this
> patch to apply. (This is relative to 1.5.2) If I get around to to
> a patch that will apply to the CVS tree as well, I will submit this
> patch again.
>
> Other than that, I believe I have tried to live up to the standards
asked
> for in Python patches.
>
> I confirm that, to the best of my knowledge and belief, this
> contribution is free of any claims of third parties under
> copyright, patent or other rights or interests ("claims"). To
> the extent that I have any such claims, I hereby grant to CNRI a
> nonexclusive, irrevocable, royalty-free, worldwide license to
> reproduce, distribute, perform and/or display publicly, prepare
> derivative versions, and otherwise use this contribution as part
> of the Python software and its related documentation, or any
> derivative versions thereof, at no cost to CNRI or its licensed
> users, and to authorize others to do so.
>
> I acknowledge that CNRI may, at its sole discretion, decide
> whether or not to incorporate this contribution in the Python
> software and its related documentation. I further grant CNRI
> permission to use my name and other identifying information
> provided to CNRI by me for use in connection with the Python
> software and its related documentation.
>
> --- urllib.py.orig Wed Jan 26 20:22:36 2000
> +++ urllib.py Wed Jan 26 20:25:06 2000
> @@ -230,11 +230,13 @@
> user_passwd, host = splituser(host)
> host = unquote(host)
> realhost = host
> + proxy_passwd = None
> else:
> host, selector = url
> urltype, rest = splittype(selector)
> url = rest
> user_passwd = None
> + proxy_passwd, host = splituser(host)
> if string.lower(urltype) != 'http':
> realhost = None
> else:
> @@ -245,6 +247,11 @@
> selector = "%s://%s%s" % (urltype, realhost,
rest)
> #print "proxy via http:", host, selector
> if not host: raise IOError, ('http error', 'no host given')
> + if proxy_passwd:
> + import base64
> + pauth = string.strip(base64.encodestring(proxy_passwd))
> + else:
> + pauth = None
> if user_passwd:
> import base64
> auth = string.strip(base64.encodestring(user_passwd))
> @@ -258,6 +265,7 @@
> else:
> h.putrequest('GET', selector)
> if auth: h.putheader('Authorization', 'Basic %s' % auth)
> + if auth: h.putheader('Proxy-Authorization', 'Basic %s' %
pauth)
> if realhost: h.putheader('Host', realhost)
> for args in self.addheaders: apply(h.putheader, args)
> h.endheaders()
>
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list