urllib2 not support proxy on SSL connection?

I

itay_k

Hi,

I am running the following simple code (just open connection to some
https page with proxy):

proxy= '666.179.227.666:80'
proxy=urllib2.ProxyHandler({"https":'https://'+proxy})
opener = urllib2.build_opener(proxy)
request = urllib2.Request('https://somehttpspage....')
response = opener.open(request)

And I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python24\lib\urllib2.py", line 358, in open
response = self._open(req, data)
File "C:\Python24\lib\urllib2.py", line 376, in _open
'_open', req)
File "C:\Python24\lib\urllib2.py", line 337, in _call_chain
result = func(*args)
File "C:\Python24\lib\urllib2.py", line 1029, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "C:\Python24\lib\urllib2.py", line 996, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error (1, 'error:140770FC:SSL
routines:SSL23_GET_SERV
ER_HELLO:unknown protocol')>

Is it possible that urllib2 doesnt support for proxy over https
connections?

Thanks alot,
Itay.
 
H

Heiko Wundram

Am Dienstag 02 Mai 2006 23:22 schrieb itay_k:
Is it possible that urllib2 doesnt support for proxy over https
connections?

Are you sure this a proxy which is accessed by https, or rather a proxy that
supports CONNECT, and thus allows you to access https-sites? I'd guess the
latter, which I haven't gotten to work with urllib2 so far.

AFAICT, that's why you get an unknown protocol error from the SSL library,
because the proxy starts a plaintext session, and urllib2 expects an SSL
session (which you try to use to access the proxy, because you specify https
as the proxy URL), and so doesn't know what to do with the data it gets.

I'd guess you'd have to rethink what you're doing here...

--- Heiko.
 
J

John J. Lee

Heiko Wundram said:
Am Dienstag 02 Mai 2006 23:22 schrieb itay_k:

Are you sure this a proxy which is accessed by https, or rather a proxy that
supports CONNECT, and thus allows you to access https-sites? I'd guess the
latter, which I haven't gotten to work with urllib2 so far.
[...]

There's a patch on SF that implements this (CONNECT), but it's fairly
nasty and would need rewriting to get into the stdlib.


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top