python AttributeError: module 'socks' has no attribute 'setdefaultproxy'

python AttributeError: module 'socks' has no attribute 'setdefaultproxy'

尝试测试 socks 模块,但在每种情况下我都得到 "AttributeError: module 'socks' has no attribute 'setdefaultproxy'"

  import socks
  import socket
  socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
  socket.socket = socks.socksocket
  import urllib2

  print(urllib2.urlopen("http://www.yahoo.com").read())

尝试:

socks.set_default_proxy(----)

嘿,正在尝试替换

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)

socks.set_default_proxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)

注意以下内容。

socks.set_default_proxy

换句话说应该是

import socks
import socket
socks.set_default_proxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
import urllib2

print(urllib2.urlopen("http://www.yahoo.com").read())

如果仍然失败,请尝试检查。 您使用的是哪个版本的袜子?,您使用的是哪个版本的 python?,因为我在 python 2.7.9 上对其进行了测试,但我没有收到您的错误。你 运行 是哪个 os?

sock: 1.5.6

https://github.com/Anorov/PySocks

http://socksipy.sourceforge.net/