我在用
import requests
requests.post(url='https://foo.example', data={'bar':'baz'})
但我得到一个 request.exceptions.SSLError。该网站有一个过期的证书,但我没有发送敏感数据,所以对我来说没关系。我想我可以使用像“verifiy=False”这样的论点,但我似乎找不到它。
原文由 Paul Draper 发布,翻译遵循 CC BY-SA 4.0 许可协议
我在用
import requests
requests.post(url='https://foo.example', data={'bar':'baz'})
但我得到一个 request.exceptions.SSLError。该网站有一个过期的证书,但我没有发送敏感数据,所以对我来说没关系。我想我可以使用像“verifiy=False”这样的论点,但我似乎找不到它。
原文由 Paul Draper 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用 requests.packages.urllib3.disable_warnings()
和 verify=False
requests
方法。
import requests
from urllib3.exceptions import InsecureRequestWarning
# Suppress only the single warning from urllib3 needed.
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
# Set `verify=False` on `requests.post`.
requests.post(url='https://example.com', data={'bar':'baz'}, verify=False)
原文由 efrenfuentes 发布,翻译遵循 CC BY-SA 4.0 许可协议
4 回答4.4k 阅读✓ 已解决
4 回答3.8k 阅读✓ 已解决
1 回答2.9k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
1 回答4.5k 阅读✓ 已解决
1 回答3.8k 阅读✓ 已解决
1 回答2.8k 阅读✓ 已解决
从 文档中:
import requests from urllib3.exceptions import InsecureRequestWarning
old_merge_environment_settings = requests.Session.merge_environment_settings
@contextlib.contextmanager def no_ssl_verification(): opened_adapters = set()
with no_ssl_verification(): requests.get(’https://wrong.host.badssl.example/’) print(‘It works’)
requests.get(’https://wrong.host.badssl.example/’, verify=False) print(‘It resets back’)
session = requests.Session() session.verify = True
with no_ssl_verification(): session.get(’https://wrong.host.badssl.example/’, verify=True) print(‘Works even here’)
try: requests.get(’https://wrong.host.badssl.example/’) except requests.exceptions.SSLError: print(‘It breaks’)
try: session.get(’https://wrong.host.badssl.example/’) except requests.exceptions.SSLError: print(‘It breaks here again’)
”`