MihoyoBBSTools/request.py

18 lines
589 B
Python
Raw Normal View History

try:
2021-10-25 14:53:34 +00:00
# 优先使用httpx在httpx无法使用的环境下使用requests
import httpx
2021-10-25 14:53:34 +00:00
2022-07-06 01:58:11 +00:00
http = httpx.Client(timeout=20, transport=httpx.HTTPTransport(retries=10))
2021-10-25 14:53:34 +00:00
# 当openssl版本小于1.0.2的时候直接进行一个空请求让httpx报错
import tools
2022-04-24 05:06:26 +00:00
2022-01-06 05:49:25 +00:00
if tools.get_openssl_version() <= 102:
httpx.get()
2022-04-24 05:06:26 +00:00
except (TypeError, ModuleNotFoundError):
import requests
2021-12-02 02:54:24 +00:00
from requests.adapters import HTTPAdapter
2022-04-24 05:06:26 +00:00
2021-12-02 02:54:24 +00:00
http = requests.Session()
2022-07-06 01:58:11 +00:00
http.mount('http://', HTTPAdapter(max_retries=10))
http.mount('https://', HTTPAdapter(max_retries=10))