小编edd*_*die的帖子

pip --version 导致打开引发 FileNotFoundError("无法打开孤立路径")

我正在努力从 Python 调用 Rest-API。我已经使用 Postman 测试了所有 Rest-API,并且工作正常。但是,在使用 Python 脚本执行这些脚本时,我遇到了认证错误。

我正在从 Windows cmd 执行 python 脚本。

下面是代码:

import requests
import certifi
from urllib.request import urlopen
import ssl

requestCert = 'https://someurl.com:4443/api/11/projects/'
urlopen(requestCert, context=ssl.create_default_context(cafile=certifi.where()))

headers = {
    "Authorization": "fdsfsfdewrwerwer",
    "X-Auth-Token": "YxzcfhnkniGVGljghjmwCIGLfhfsfdzxc4o5sSADtaT2"
}

#response = requests.get('https://someurl.com:4443/api/11/projects', headers=headers)
#response = requests.get('https://someurl.com:4443/api/11/projects', headers=headers, verify=certifi.where())
response = requests.get('https://someurl.com:4443/api/11/projects', headers=headers, verify='server.pem')

print(response)
Run Code Online (Sandbox Code Playgroud)

进一步调试。。。即使简单import requests print('Hello, world!')pip install requests给出相同的错误。我想问题不在代码中,而是与模块导入功能有关。

我收到的错误如下。

Traceback (most recent call last):
  File "C:\Users\eddie\Desktop\PyPoc\Py_Job\importJob.py", line 1, in <module>
    import requests
  File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\__init__.py", …
Run Code Online (Sandbox Code Playgroud)

python api python-2.7 python-3.x python-requests

1
推荐指数
1
解决办法
2837
查看次数

标签 统计

api ×1

python ×1

python-2.7 ×1

python-3.x ×1

python-requests ×1