Skip to content

Commit a8a6c09

Browse files
update json return
1 parent 1e60d82 commit a8a6c09

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

app.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,9 @@ async def fetch_data(url):
153153
async with aiohttp.ClientSession() as session:
154154
async with session.get(url) as response:
155155
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:
156+
try:
159157
return await response.json()
160-
else:
158+
except (aiohttp.ContentTypeError, json.JSONDecodeError):
161159
return await response.text()
162160
else:
163161
return f"Request failed with status code {response.status}"

0 commit comments

Comments
 (0)