Anorov/PySocks

AttributeError using socks5 with requests[socks]

dorazouri opened this issue · 4 comments

Using requests with a socks5 proxy fails on:
AttributeError: 'super' object has no attribute 'settimeout'

Reproduction Steps

pip install requests[socks]==2.14.2
(this installs PySocks v1.6.7)

run a socks proxy on port 9050. I use Tor for that matter.

Simplified code I use is:

import requests
proxies={'http': 'socks5://127.0.0.1:9050'}
url = 'http://www.whatismyip.org/'
requests.get(url, proxies=proxies)

System Information

Windows 7 (x64): 6.1.7601
Python 2.7.12 64bit

Full Traceback

File "c:\Python27\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "c:\Python27\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "c:\Python27\lib\site-packages\requests\sessions.py", line 518, in request
resp = self.send(prep, **send_kwargs)
File "c:\Python27\lib\site-packages\requests\sessions.py", line 639, in send
r = adapter.send(request, **kwargs)
File "c:\Python27\lib\site-packages\requests\adapters.py", line 438, in send
timeout=timeout
File "c:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "c:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 356, in _make_request
conn.request(method, url, **httplib_request_kw)
File "c:\python27\Lib\httplib.py", line 1057,in request
self._send_request(method, url, body, headers)
File "c:\python27\Lib\httplib.py", line 1097, in _send_request
self.endheaders(body)
File "c:\python27\Lib\httplib.py",line 1053, in endheaders
self._send_output(message_body)
File "c:\python27\Lib\httplib.py", line 897, in _send_output
self.send(msg)
File "c:\python27\Lib\httplib.py", line 859,in send
self.connect()
File "c:\Python27\lib\site-packages\requests\packages\urllib3\connection.py", line 166, in connect
conn = self._new_conn()
File "c:\Python27\lib\site-packages\requests\packages\urllib3\contrib\socks.py", line 88, in _new_conn
**extra_kw
File "c:\Python27\lib\site-packages\socks.py", line 229, in create_connection
sock.connect((remote_host, remote_port))
File "c:\Python27\lib\site-packages\socks.py", line 96, in wrapper
return function(*args, **kwargs)
File "c:\Python27\lib\site-packages\socks.py", line 781, in connect
super(socksocket, self).settimeout(self._timeout)
AttributeError: 'super' object has no attribute 'settimeout'

Extras

I want to suggest the closest issue I have found, that is on gevent:
gevent/gevent#937

Replacing all occurences of (in socks.py):
super(socksocket, self).settimeout
with:
self.settimeout
solves the issue, but I don't know if there are any other side effects

Root cause found, not related to PySocks. Thanks.

@dorazouri What was it? How can I fix it?

@metashock I had a socket wrapper in my testing environment that altered the socket attributes. It had a fault that removed some attributes, settimeout was one of them.