gpt4 book ai didi

从终端使用 SOCKS5 时 Python 的请求为 "Missing dependencies for SOCKS support"

转载 作者:行者123 更新时间:2023-12-03 07:52:14 28 4
gpt4 key购买 nike

我正在尝试使用依赖于 Python 请求的包与我的 Python 2.7 shell 中的 API 进行交互。问题是我的网络(大学图书馆)阻止了远程地址。

说到 API,我执行以下操作:

~$ ssh -D 8080 name@myserver.com

然后,在新终端中,在本地计算机中:
~$ export http_proxy=socks5://127.0.0.1:8080 https_proxy=socks5://127.0.0.1:8080

然后我在 Python 控制台中运行程序但失败了:
~$ python
>>> import myscript
>>> id = '1213'
>>> token = 'jd87jd9'
>>> connect(id,token)

File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 518, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 585, in send
r = adapter.send(request, **kwargs)
File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 370, in send
conn = self.get_connection(request.url, proxies)
File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 273, in get_connection
proxy_manager = self.proxy_manager_for(proxy)
File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 169, in proxy_manager_for
**proxy_kwargs
File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 43, in SOCKSProxyManager
raise InvalidSchema("Missing dependencies for SOCKS support.")
requests.exceptions.InvalidSchema: Missing dependencies for SOCKS support.

此摘录来自 adapters.py requests module :
> try:
> from .packages.urllib3.contrib.socks import SOCKSProxyManager except ImportError:
> def SOCKSProxyManager(*args, **kwargs):
> raise InvalidSchema("Missing dependencies for SOCKS support.")

现在问题似乎起源于 urllib3 的 SOCKSProxyManager。

所以我读到如果您安装了 PySocks,您可以将 SOCKSProxyManager 与 SOCKS5 一起使用或者你做一个 pip install urllib3[socks]

唉,我用 Socks 尝试了 PySocks 和 urllib3,但没有成功。

知道另一种解决方法吗?

编辑:

我还尝试了 pip install requests[socks] (这是带有 Socks 支持的 requests 2.10.0),我得到了这个:
  File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 467, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: SOCKSHTTPSConnectionPool(host='api-server.com', port=443): Max retries exceeded with url: /auth (Caused by NewConnectionError('<requests.packages.urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x95c7ccc>: Failed to establish a new connection: SOCKS5 proxy server sent invalid data',))

最佳答案

我在 conda 和请求 2.11 上遇到了同样的问题(我在公司代理后面的 Ubuntu VM 中工作)。

This issue帮助过我。我更改了环境变量 all_proxy (最初设置为 SOCK 代理 socks://.... )到我的 .bashrc 文件中的 https 版本:
export all_proxy="https://<proxy>:<port>/"
现在它起作用了。

关于从终端使用 SOCKS5 时 Python 的请求为 "Missing dependencies for SOCKS support",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38794015/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com