首页 > 解决方案 > pip._vendor 奇怪的行为,但请求有效

问题描述

运行我的代码时遇到问题。我看到以下错误。有趣的是,当我将此代码带到其他环境(例如visual code代码正在运行)并且我得到响应时...我认为自动添加的from pip._vendor import请求有问题pycharm。例如,visual code正在添加imports requests并且它可以工作。我应该怎么做这个代码才能正确运行pycharm

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed
 to respond

During handling of the above exception, another exception occurred:
 self, "Failed to establish a new connection: %s" % e
pip._vendor.urllib3.exceptions.NewConnectionError: <pip._vendor.urllib3.connection.HTTPSConnection object at 0x00000217D0A2B9C8>: Failed to establish a new connection: [WinError 10060] A connection atte
mpt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
 raise MaxRetryError(_pool, url, error or ResponseError(cause))
pip._vendor.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='xxx.xxx', port=443): Max retries exceeded with url: /api/ser (Caused by NewConnectionError('<pip._vend
or.urllib3.connection.HTTPSConnection object at 0x00000217D0A2B9C8>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respo
nd after a period of time, or established connection failed because connected host has failed to respond'))

这是我的代码:

from pip._vendor import requests


if __name__ == '__main__':
    print(msg)

    data = {
        "Ex": 22
        }
    }

    headers = {
        "Authorization": "Bearer xxxx"
    }

    response = requests.post("https://xxx.xxx/api/ser", headers=headers, json=data)

    print(response.json())

标签: pythonvisual-studio-codepycharm

解决方案


您正在导入库的_vendor导入pip。它可以工作,但你可以这样做import requests(如果它已经安装)。


推荐阅读