Why do I see an error
Error while making request to
https://data.similarweb.com/api/v1/data?domain=httpbin.org: Expecting
value: line 1 column 1 (char 0)
with aiohttp
while requests.get
returns the correct json?
import aiohttp
import asyncio
import nest_asyncio
nest_asyncio.apply()
async def fetch(session, url):
try:
async with session.get(url, headers=headers) as response:
return await response.json(content_type=None)
except Exception as e:
print(f"Error while making request to {url}: {str(e)}")
async def fetch_all(urls):
async with aiohttp.ClientSession() as session:
tasks = []
for url in urls:
tasks.append(fetch(session, url))
responses = await asyncio.gather(*tasks, return_exceptions=True)
return responses
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
}
urls = ['https://data.similarweb.com/api/v1/data?domain=' + 'httpbin.org']
responses = asyncio.run(fetch_all(urls))
httpbin.org/headers
returns exactly the same headers with the only difference in X-Amzn-Trace-Id
value.