【问题标题】:pip._vendor strange behaviour but requests workspip._vendor 奇怪的行为,但请求有效
【发布时间】:2021-08-16 12:46:17
【问题描述】:

运行代码时遇到问题。我看到以下错误。有趣的是,当我将此代码带到 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())

【问题讨论】:

  • 如果它也可以通过 CLI 运行,请注意您的防火墙/防病毒设置。

标签: python visual-studio-code pycharm


【解决方案1】:

您正在导入 pip 库的 _vendor 导入。它可以工作,但您可以改为使用import requests(如果已安装)。

【讨论】:

    猜你喜欢
    • 2013-06-24
    • 2021-05-26
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    相关资源
    最近更新 更多