我正在使用 Python 3.7.3 对我网站上托管的 PHP 文件运行 GET 请求。但是,当我运行它时,我收到以下错误。我已经requests
通过pip3
Homebrew 安装了。我正在使用 macOS Mojave。
回溯(最近调用最后):
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py”,第 600 行,在 urlopen chunked=chunked)
文件中“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py”,第 343 行,在 _make_request self._validate_conn(conn)
文件“/Library/Frameworks/Python .framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py”,第 839 行,在 _validate_conn conn.connect()
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib /python3.7/site-packages/urllib3/connection.py”,第 344 行,在连接 ssl_context=context 中)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/util/ssl_.py”,第 344 行,在 ssl_wrap_socket
返回 context.wrap_socket(sock, server_hostname=server_hostname)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”,第 412 行,在 wrap_socket session=session
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib /python3.7/ssl.py”,第 853 行,在 _create self.do_handshake()
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”,第 1117 行,在do_handshake self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)在处理上述异常的过程中,又出现了一个异常:
追溯(最近调用最后):
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/adapters.py”,第 449 行,在发送超时=超时
文件“ /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py”,第 638 行,在 urlopen _stacktrace=sys.exc_info()[2])
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/util/retry.py”,第 398 行,递增 raise MaxRetryError(_pool, url, error or ResponseError(原因)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='ijetlab.com', port=443): 最大重试次数超过 url: /api/api.php?one=1&two=2 (由 SSLError(SSLCertVerificationError(1 , '[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)')))在处理上述异常的过程中,又出现了一个异常:
回溯(最近一次调用最后一次):
文件“/Users/maxwellnewberry/Documents/test.py”,第 12 行,在 r = requests.get(url = URL, params = PARAMS)
文件“/Library/Frameworks/Python.framework /Versions/3.7/lib/python3.7/site-packages/requests/api.py”,第 75 行,在 get return request('get', url, params=params, **kwargs)
File “/Library/Frameworks /Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/api.py”,第60行,在请求返回session.request(method=method, url=url, **kwargs)
File” /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py”,第 533 行,请求 resp = self.send(prep, **send_kwargs)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py”,第 646 行,在 send r = adapter.send(request, **kwargs)
文件中“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/adapters.py”,第 514 行,在发送中引发 SSLError(e, request=request) requests.exceptions.SSLError : HTTPSConnectionPool(host='ijetlab.com', port=443): 最大重试次数超过 url: /api/api.php?one=1&two=2 (由 SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 证书引起验证失败:无法获取本地颁发者证书 (_ssl.c:1056)')))
这是代码:
# importing the requests library
import requests
# api-endpoint
URL = "https://ijetlab.com/api/api.php"
# defining a params dict for the parameters to be sent to the API
PARAMS = {'one':1, 'two':2}
# sending get request and saving the response as response object
r = requests.get(url = URL, params = PARAMS)
# extracting data in json format
data = r.json()
print(data['response'])
所有搜索都告诉我运行“Install Certificates.command”,我已经运行了大约 100 次。我也让客户安装了证书。