【问题标题】:requests.exceptions.InvalidSchema: Missing dependencies for SOCKS supportrequests.exceptions.InvalidSchema:缺少对 SOCKS 支持的依赖项
【发布时间】:2019-08-15 14:04:05
【问题描述】:

我想尝试使用代理请求打开页面。 https://stackoverflow.com/…/make-requests-using-python-over… 我有这个代码:

def get_tor_session():
session = requests.session()
# Tor uses the 9050 port as the default socks port
session.proxies = {'http': 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'}
return session

# Make a request through the Tor connection
# IP visible through Tor
session = get_tor_session()
print(session.get("http://httpbin.org/ip").text)
# Above should print an IP different than your public IP

# Following prints your normal public IP
print(requests.get("http://httpbin.org/ip").text)

但我明白了:

requests.exceptions.InvalidSchema: Missing dependencies for SOCKS support.

我该怎么办? 谢谢

【问题讨论】:

标签: python proxy ip tor


【解决方案1】:

这意味着 requests 使用 socks 作为代理,并且未安装 socks。

只需运行 pip install pysocks

【讨论】:

    【解决方案2】:

    为了使requests使用socks代理,你需要安装它的依赖。

    pip install requests requests[socks]
    

    【讨论】:

      猜你喜欢
      • 2019-08-09
      • 2017-04-16
      • 2017-12-25
      • 2015-04-18
      • 2020-03-24
      • 2012-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多