We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1e60d82 commit a8a6c09Copy full SHA for a8a6c09
app.py
@@ -153,11 +153,9 @@ async def fetch_data(url):
153
async with aiohttp.ClientSession() as session:
154
async with session.get(url) as response:
155
if response.ok:
156
- # Check if the response content type is JSON
157
- content_type = response.headers.get('Content-Type', '').lower()
158
- if 'application/json' in content_type:
+ try:
159
return await response.json()
160
- else:
+ except (aiohttp.ContentTypeError, json.JSONDecodeError):
161
return await response.text()
162
else:
163
return f"Request failed with status code {response.status}"
0 commit comments