470,870 Members | 1,191 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

urllib2 : https and proxy

Hello all,

I'm facing a strange behavior of urllib2 trying to access gmail
account behind a proxy (Squid).

The following works perfectly :

wget --save-cookies cookies --keep-session-cookies --post-
data="Em*************************@gmail.com&Passwd =cpfinances" --no-
check-certificate -O - https://www.google.com/accounts/ServiceLoginBoxAuth
While the following urllib2 code fail with an error 501 :

In [18]: import urllib2

In [19]: r=urllib2.urlopen("https://www.google.com/accounts/

"Em*************************@gmail.com&Passwd=cpfi nances")
urllib2.HTTPError Traceback (most
recent call last)

/home/maric/<ipython console>

/home/maric/urllib2.py in urlopen(url, data)
128 if _opener is None:
129 _opener = build_opener()
--130 return _opener.open(url, data)


/home/maric/urllib2.py in http_error_default(self, req, fp, code, msg,
478 class HTTPDefaultErrorHandler(BaseHandler):
479 def http_error_default(self, req, fp, code, msg, hdrs):
--480 raise HTTPError(req.get_full_url(), code, msg, hdrs,
482 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 501: Not Implemented
I understood it's a response from the proxy about incompatible
protocols and queries but this seem rather strange in this case. Could
there be a bug in the ProxyHandler class ? Any idea about what could
cause this error on the proxy ?

Jun 28 '07 #1
1 3680
* Maric Michaud <ma***@aristote.info[2007-06-28 23:38:39]:
Hmmm, i've tried something similar but I get the same result.

For the code example I gave, I've put correctly the http_proxy and
https_proxy environment variables, the default ProxyHandler get them right
as this is the proxy itself which returns the error. I checked this with
wireshark, the proxy said that there is incompatibilities in some request
methods, like POST, with some protocols, Gopher is the example it gave.
That doesn't make much sense to me as the wget command I tried is intended
to do exactly the same thing (POST over https and retrieve some cookies from
the response), and go through with no problems.
Maric, in the ActiveState urllib2 HOWTO which seems to apply for Python 2.5, I
came across a point which mentions urllib2 does not support PROXY for HTTPS.
Your case seems the same, I would suggest you to look up the Python Tracker
for any already open issues, or if not kindly log one yourself.
I shall if I can help further, working on urllib2 is a project am doing as
part of Summer of Code 2007.


O.R.Senthil Kumaran
Jul 2 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by O. Koch | last post: by
4 posts views Thread by news.easynet.be | last post: by
reply views Thread by Benjamin Schollnick | last post: by
reply views Thread by Fuzzyman | last post: by
1 post views Thread by Ray Slakinski | last post: by
3 posts views Thread by itay_k | last post: by
reply views Thread by Ali.Sabil | last post: by
1 post views Thread by Astan Chee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.