running sockshandler.py problem
Opened this issue · 3 comments
I ran sockshandler.py in the git.
Of course, I changed proxy server address and port accordingly.
Requesting http works well, while requesting from https site met with problems.
I tested a several sites, including example site https://httpbin.org/ip
Results are below, I wonder why it does not work with ssl. Thank you.
HTTP: {
"origin": "107.178.200.206"
}
HTTPS:
Traceback (most recent call last):
File "sockshandler.py", line 61, in
print "HTTPS:", opener.open("https://httpbin.org/ip").read()
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "sockshandler.py", line 55, in https_open
return self.do_open(build, req)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:581)>
What kind of proxy and proxy protocol are you using? Also, does the same code work if you monkeypatch socket.socket
directly instead of using the urllib2 handler?
I use goagent proxy, whose protocol is http.
instead of using the urllib2 handler, monkeypatch socket.socket directly works well.
also, urllib works well.
It is not advised to use PySocks for HTTP proxies; I even considered removing support entirely. HTTP proxies are much better handled at the HTTP client level rather than the "proxy middleware" level.
I'd recommend using urllib2's own ProxyHandler
instead.
Or, switch to urllib3 or requests and use their HTTP proxy functionality.