Python调用API报错 SSL Max retries exceeded with _ssl.c:1129
主程序是调用PUBG的API来获取玩家数据,脚本没有用到代{过}{滤}理,偶尔会出现以下报错信息我的程序代码:
```py
import requests
from datetime import datetime, timedelta
from PIL import Image, ImageDraw, ImageFont
import sys
import os
import requests
from PIL import Image
from io import BytesIO
import requests.exceptions
player_id = sys.argv if len(sys.argv) > 1 else ""
headers = {
"Authorization": "Bearer api key",
"Accept": "application/vnd.api+json"
}
def get_player_data(player_id):
url = f"https://api.pubg.com/shards/steam/players?filter={player_id}"
try:
response = requests.get(url, headers=headers)
except requests.exceptions.RequestException as e:
print(f"error:{e}")
sys.exit(3)
if response.status_code == 429:
sys.exit(2)
elif response.status_code in :
sys.exit(1)
else:
data = response.json()
ban_type = data['data']['attributes']['banType'] if 'data' in data and data['data'] else None
account_id = data['data']['id'] if 'data' in data and data['data'] else None
return data, ban_type, account_id
```
环境:
```
C:\Users\Administrator\AppData\Local\Programs\Python\Python39\python.exe
OS Windows-2012ServerR2-6.3.9600-SP0
Python 3.9.13
OpenSSL 1.1.1n15 Mar 2022
urllib3 1.25.11
```
错误信息:
```
HTTPSConnectionPool(host='api.pubg.com', port=443):
Max retries exceeded with url: /shards/steam/players?filter%5BplayerNames%5D=Dai
lyMidv_x (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protoc
ol (_ssl.c:1129)')))
``` 国际网站总会有点干扰,晚上出现会更加频繁 verify=False 这个试试。
verify=False 这个试试。 应该是开启了抓包程序就报这个错。关闭抓包程序才行 可以增加黑色加粗部分response = requests.get(url, headers=headers , verify=False)
或者用session()请求
response = requests.session() 1. 尝试关闭代{过}{滤}理
2. 或者,verify参数设置为False
import requests
res = requests.get(url="https://www.xxxxx.com",verify=False)#不验证证书,报警告,返回200
print(res.content.decode("utf-8"))
3. 或者,忽略SSL认证
import requests,warnings
from requests.packages import urllib3
urllib3.disable_warnings()
warnings.filterwarnings("ignore") Do_zh 发表于 2024-7-29 08:46
verify=False 这个试试。
这个我试过感觉是可以的,但是关闭ssl验证会不会出问题 xqdyan 发表于 2024-7-29 09:05
可以增加黑色加粗部分response = requests.get(url, headers=headers , verify=False)
或者用session()请 ...
session()请求效果怎么样
页:
[1]