null update info
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
<<<<<<< HEAD
|
||||
import requests
|
||||
import json
|
||||
from requests.exceptions import RequestException
|
||||
@@ -28,35 +27,4 @@ def _make_request(method: str, url: str, headers: dict, params: dict = None, nor
|
||||
except json.JSONDecodeError:
|
||||
return {"error": response.text}
|
||||
except RequestException as e:
|
||||
=======
|
||||
import requests
|
||||
import json
|
||||
from requests.exceptions import RequestException
|
||||
import platform
|
||||
|
||||
UA = f"SolianForPythonApp/0.000.001 ({platform.system()})"
|
||||
|
||||
def _make_request(method: str, url: str, headers: dict, params: dict = None, normal_codes: list = [200], request_body: dict = None) -> dict:
|
||||
"""内部辅助函数,用于发送HTTP请求并处理响应"""
|
||||
headers['User-Agent'] = UA
|
||||
try:
|
||||
if method == 'GET':
|
||||
response = requests.get(url, headers=headers, params=params)
|
||||
elif method == 'POST':
|
||||
response = requests.post(url, headers=headers, data=json.dumps(request_body))
|
||||
elif method == 'DELETE':
|
||||
response = requests.delete(url, headers=headers, params=params)
|
||||
elif method == 'PATCH':
|
||||
response = requests.patch(url, headers=headers, data=json.dumps(request_body))
|
||||
else:
|
||||
return {"error": "Unsupported HTTP method"}
|
||||
|
||||
if response.status_code not in normal_codes:
|
||||
return {"error": f"Unexpected status code: {response.status_code}"}
|
||||
|
||||
return response.json()
|
||||
except json.JSONDecodeError:
|
||||
return {"error": response.text}
|
||||
except RequestException as e:
|
||||
>>>>>>> 967cea4c47a481e79c92fda0760c423de7fbcedf
|
||||
return {"error": str(e)}
|
Reference in New Issue
Block a user