Python无法使用pip,也可能是因为同样的原因无法使用pythontelegramb库

2024-09-28 22:06:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个相当奇怪的问题,尽管我花了相当长的时间在谷歌上搜索,但我还是无法解决。在

首先当我想在virtualenv中使用pip搜索或安装软件包时,我得到以下信息:

~$ ./virenv/bin/pip search telegram

Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fee3a528e90>: Failed to establish a new connection: [Errno 111] Connection refused',))': /pypi
...
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fee3a4ca2d0>: Failed to establish a new connection: [Errno 111] Connection refused',))': /pypi


Exception:
Traceback (most recent call last):
 File "~/virenv/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
...
ProxyError: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /pypi (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fee3a4ca390>: Failed to establish a new connection: [Errno 111] Connection refused',)))

我不支持代理,我可以参选

^{pr2}$

而且效果很差。 我的pip版本:

~$ ./virenv/bin/pip -V
pip 9.0.1 from ~/virenv/local/lib/python2.7/site-packages (python 2.7)

我检查了人们拥有的here补丁,但是这些代码行已经出现在我的pip包中了。同时更换

~/Test/virenvTest/lib/python2.7/site-packages/pip//u vendor/requests/packages/urllib3/连接.py 用一个here(因为它似乎包括额外的行)是没有用的。以及对

python2.6/site-packages/pip//u供应商/请求/适配器.py

上面提到的here(由alexandrem编写)似乎不可能,因为这行代码有不同的逻辑。在

我知道我只是在摸索

第二个(另一个症状)在Pycharm中,我可以毫无问题地安装包并运行代码。但当我试图从命令行运行这个script(这需要到Internet上)时,还是要这样

$ ~/virenv/bin/python ~/PycharmProjects/bot/test1.py

2017-12-04 16:59:30,278 - telegram.vendor.ptb_urllib3.urllib3.connectionpool - WARNING - Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x7fa159cd1650>: Failed to establish a new connection: [Errno 111] Connection refused',))': /botXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/setWebhook
...
2017-12-04 16:59:30,280 - telegram.vendor.ptb_urllib3.urllib3.connectionpool - WARNING - Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x7fa159cd18d0>: Failed to establish a new connection: [Errno 111] Connection refused',))': /botXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/setWebhook
2017-12-04 16:59:30,280 - telegram.ext.updater - ERROR - error in bootstrap phase; try=0 max_retries=0
Traceback (most recent call last):
  File "~/virenv/local/lib/python2.7/site-packages/telegram/utils/request.py", line 196, in _request_wrapper
raise NetworkError('urllib3 HTTPError {0}'.format(error))
...
NetworkError: urllib3 HTTPError HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /botXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/setWebhook (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x7fa159cd1990>: Failed to establish a new connection: [Errno 111] Connection refused',)))
2017-12-04 16:59:30,300 - telegram.ext.updater - ERROR - unhandled exception
...
NetworkError: urllib3 HTTPError HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /botXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/setWebhook (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x7fa159cd1990>: Failed to establish a new connection: [Errno 111] Connection refused',)))


2017-12-04 16:59:31,282 - telegram.ext.dispatcher - CRITICAL - stopping due to exception in another thread

似乎这两种情况都有问题(我不确定,因为我在这个领域是一个平庸的人),可能是pythonurllib3包,但我应该如何修复它?有人帮忙吗!在


Tags: piptononebypackagesconnectconnectionproxy