MihoyoBBSTools/request.py
2022-07-06 09:58:11 +08:00

18 lines
589 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

try:
# 优先使用httpx在httpx无法使用的环境下使用requests
import httpx
http = httpx.Client(timeout=20, transport=httpx.HTTPTransport(retries=10))
# 当openssl版本小于1.0.2的时候直接进行一个空请求让httpx报错
import tools
if tools.get_openssl_version() <= 102:
httpx.get()
except (TypeError, ModuleNotFoundError):
import requests
from requests.adapters import HTTPAdapter
http = requests.Session()
http.mount('http://', HTTPAdapter(max_retries=10))
http.mount('https://', HTTPAdapter(max_retries=10))