Улучшение обработки запросов к VNDB API и изменение структуры полей в ответах
This commit is contained in:
@@ -55,30 +55,20 @@ class VndbClient:
|
||||
method: str = "GET",
|
||||
data: Optional[Dict[str, Any]] = None,
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Make HTTP request to VNDB API
|
||||
|
||||
Args:
|
||||
endpoint: API endpoint
|
||||
method: HTTP method (GET, POST, PATCH, DELETE)
|
||||
data: Request body data
|
||||
|
||||
Returns:
|
||||
Response JSON
|
||||
|
||||
Raises:
|
||||
httpx.HTTPError: On HTTP errors
|
||||
json.JSONDecodeError: On invalid JSON response
|
||||
"""
|
||||
|
||||
url = f"{self.base_url}{endpoint}"
|
||||
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
|
||||
async with httpx.AsyncClient(timeout=15) as client:
|
||||
response = await client.request(
|
||||
method,
|
||||
url,
|
||||
headers=self.headers,
|
||||
content=json.dumps(data) if data else None,
|
||||
json=data if data else None, # 🔥 ВАЖНО: json= вместо content=
|
||||
)
|
||||
|
||||
if response.status_code >= 400:
|
||||
print("VNDB ERROR:", response.status_code, response.text)
|
||||
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user