I am trying aiohttp
and asyncio
first time and getting error like
[WinError 10054] An existing connection was forcibly closed by the remote host
but same url when i fetch with requests
it working properly.so what does this error mean and how to solve it ?
my code
import aiohttp
import asyncio
url = 'https://nseindia.com/api/historical/fo/derivatives?&from=24-01-2020&to=24-01-2020&expiryDate=06-FEB-2020&instrumentType=OPTIDX&symbol=NIFTY&csv=true'
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"}
async def get_data():
async with aiohttp.ClientSession(headers=headers) as session:
async with session.get(url) as resp:
result = await resp.text()
return result
async def main():
result = await get_data()
return result
asyncio.run(main())
httpx
package instead. Also try using httpx.AsyncClient withhttp2=True
– Carson