通过Tor连接时SocksiPy失败

时间:2014-01-26 00:06:02

标签: python urllib2 socks tor httplib

尝试以下3种方法来控制Tor:

每个都失败了同样的错误(试图尽可能清楚):

Traceback (most recent call last):

File "tor.py", line 26, in <module>
  print(urllib2.urlopen("http://www.ifconfig.me/ip").read())

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py"
line 127, in urlopen
  return _opener.open(url, data, timeout)
line 404, in open
  response = self._open(req, data)
line 422, in _open
  '_open', req)
line 382, in _call_chain
  result = func(*args)
line 1214, in http_open
  return self.do_open(httplib.HTTPConnection, req)
line 1181, in do_open
  h.request(req.get_method(), req.get_selector(), req.data, headers)

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py"
line 973, in request
  self._send_request(method, url, body, headers)
line 1007, in _send_request
  self.endheaders(body)
line 969, in endheaders
  self._send_output(message_body)
line 829, in _send_output
  self.send(msg)
line 791, in send
  self.connect()
line 772, in connect
  self.timeout, self.source_address)

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py"
line 562, in create_connection
  sock.connect(sa)

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SocksiPy_branch-1.01-py2.7.egg/socks.py"
line 392, in connect
  self.__negotiatesocks5(destpair[0],destpair[1])
line 199, in __negotiatesocks5
  self.sendall("\x05\x01\x00")
line 165, in sendall
  socket.socket.sendall(self, bytes)

...上次错误重复了很多次然后......

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SocksiPy_branch-1.01-py2.7.egg/socks.py", line 163, in sendall
  if 'encode' in dir(bytes):
RuntimeError: maximum recursion depth exceeded while calling a Python object

有谁知道它的来源?

2 个答案:

答案 0 :(得分:2)

对我来说,实际上失败,并在{pip}安装了socksipy-branch

但是,我将{socks.py直接从http://socksipy.sourceforge.net/下载到我的工作目录后工作正常。

答案 1 :(得分:1)

看起来您正在使用SocksiPy库。我遇到了同样的问题,并通过直接从https://code.google.com/p/socksipy-branch/再次安装此库来解决此问题。我第一次通过pip安装它。