一、問題描述
運行以下代碼
#!/usr/local/bin/python3.7 import requests import ssl # 請求url url = 'https://cn.bing.com/tlookupv3?isVertical=1&&IG=1E1AE90B09BB41E28506E0ADC9E45704&IID=translator.5028.2' # 請求頭 headers = { 'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36' } # 請求formdata formdata = { 'from': 'en', 'to': 'zh-Hans', 'text': 'dog' } # 發送請求 r = requests.post(url, headers=headers, data=formdata) print(r.json())
報錯如下:
requests.exceptions.SSLError: HTTPSConnectionPool(host='cn.bing.com', port=443): Max retries exceeded with url: /tlookupv3?isVertical=1&&IG=1E1AE90B09BB41E28506E0ADC9E45704&IID=translator.5028.2 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1076)')))
二、報錯原因
電腦連打開了代理
三、解決方案
關閉代理即可。