Questions tagged [aiohttp]

Use this tag for questions about AIOHTTP – a client/server framework for asyncio Python.

AIOHTTP is an asynchronous asyncio Python web framework for both client and server sides. It supports HTTP, WebSockets, and also MiddleWare and Signals mechanics for the server side.

Useful links:

Related tags:

1628 questions
22
votes
3 answers

Asyncio RuntimeError: Event Loop is Closed

I'm trying to make a bunch of requests (~1000) using Asyncio and the aiohttp library, but I am running into a problem that I can't find much info on. When I run this code with 10 urls, it runs just fine. When I run it with 100+ urls, it breaks and…
Patrick Allen
  • 2,148
  • 2
  • 16
  • 20
21
votes
1 answer

Multiple loops with asyncio

Is it possible to have multiple loops with asyncio? If the response is yes how can I do that? My use case is: * I extract urls from a list of websites in async * For each "sub url list", I would crawl them in async/ Example to extract…
Matt
  • 4,309
  • 7
  • 38
  • 52
20
votes
2 answers

aiohttp module - import error

Installed aiohttp, pip3 install aiohttp as mentioned here With python3.6, I see below error: import aiohttp ModuleNotFoundError: No module named 'aiohttp' How to resolve this error?
overexchange
  • 15,768
  • 30
  • 152
  • 347
19
votes
3 answers

Using Aiohttp with Proxy

I am trying to use async to get the HTML from a list of urls (identified by ids). I need to use a proxy. I am trying to use aiohttp with proxies like below: import asyncio import aiohttp from bs4 import BeautifulSoup ids = ['1', '2', '3'] async…
yl_low
  • 1,209
  • 2
  • 17
  • 26
19
votes
3 answers

How to check a SSL certificate expiration date with aiohttp?

I know how to get certificate information such as expiration date using pyopenssl for instance, but is it possible to do it with a aiohttp response object?
azmeuk
  • 4,026
  • 3
  • 37
  • 64
18
votes
4 answers

How can I wait for an object's __del__ to finish before the async loop closes?

I have a class that will have an aiohttp.ClientSession object in it. Normally when you use async with aiohttp.ClientSession() as session: # some code The session will close since the session's __aexit__ method is called. I cant use a context…
Ron Serruya
  • 3,988
  • 1
  • 16
  • 26
18
votes
2 answers

Python aiohttp/asyncio - how to process returned data

Im in the process of moving some synchronous code to asyncio using aiohttp. the synchronous code was taking 15 minutes to run, so I'm hoping to improves this. I have some working code which gets data from some urls and returns the body of each. But…
AlexW
  • 2,843
  • 12
  • 74
  • 156
18
votes
1 answer

Does Python asyncio use a thread pool?

I wrote this bit of code: import asyncio import threading from aiohttp import ClientSession async def fetch(url): async with ClientSession() as session: async with session.get(url) as response: response = await…
lorenzocastillo
  • 985
  • 3
  • 13
  • 24
18
votes
3 answers

Multiple aiohttp Application()'s running in the same process?

Can two aiohttp.web.Application() objects be running in the same process, e.g. on different ports? I see a bunch of examples of aiohttp code like: from aiohttp import web app = web.Application() app.router.add_get('/foo', foo_view,…
Frank T
  • 8,268
  • 8
  • 50
  • 67
18
votes
2 answers

Asyncio + aiohttp - redis Pub/Sub and websocket read/write in single handler

I'm currently playing with aiohttp to see how it will perform as a server application for mobile app with websocket connection. Here is simple "Hello world" example (as gist here): import asyncio import aiohttp from aiohttp import web class…
Michael
  • 481
  • 2
  • 6
  • 13
17
votes
2 answers

python aiohttp into existing event loop

I'm testing aiohttp and asyncio. I want the same event loop to have a socket, http server, http client. I'm using this sample code: @routes.get('/') async def hello(request): return web.Response(text="Hello, world") app =…
user3599803
  • 6,435
  • 17
  • 69
  • 130
17
votes
2 answers

python async post requests

I was wondering if there was any way to make this script a lot faster - like instantly create 1000 accounts for example or at least in a matter of a few seconds. I’ve tried doing some async stuff myself but this is as far as I could get, I am just…
Kevin
  • 364
  • 1
  • 2
  • 13
16
votes
2 answers

Response payload is not completed using asyncio/aiohttp

I've written a Python 3.7 script that asynchronously (asyncio 3.4.3 and aiohttp 3.5.4) creates a Salesforce bulk API (v45.0) job/batch using multiple objects queried by a single SOQL statement each, waits for the batches to complete, upon completion…
gbeaven
  • 1,522
  • 2
  • 20
  • 40
16
votes
2 answers

aiohttp how to save a persistent ClientSession in a class?

I'm writing a class that will do http requests using aiohttp. According to the docs I should not to create a ClientSession per request, so I want to reuse the same session. code: class TestApi: def __init__(self): self.session =…
user3599803
  • 6,435
  • 17
  • 69
  • 130
16
votes
3 answers

aiohttp client_exception ServerDisconnectedError - is this the API server's issue or aiohttp or my code?

I'm getting an aiohttp client_exception.ServerDisconnectedError whenever I do more than ~200 requests to an API I'm hitting using asyncio & aiohttp. It doesn't seem to be my code because it works consistently with smaller number of requests, but…
hyphen
  • 2,368
  • 5
  • 28
  • 59