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
27
votes
1 answer

asyncio aiohttp progress bar with tqdm

I'm attempting to integrate a tqdm progress bar to monitor POST requests generated with aiohttp in Python 3.5. I have a working progress bar but can't seem to gather results using as_completed(). Pointers gratefully received. Examples I've found…
Bede Constantinides
  • 2,424
  • 3
  • 25
  • 28
26
votes
2 answers

asyncio web scraping 101: fetching multiple urls with aiohttp

In earlier question, one of authors of aiohttp kindly suggested way to fetch multiple urls with aiohttp using the new async with syntax from Python 3.5: import aiohttp import asyncio async def fetch(session, url): with aiohttp.Timeout(10): …
Hans Schindler
  • 1,787
  • 4
  • 16
  • 25
25
votes
2 answers

How can I mock out responses made by aiohttp.ClientSession?

I am using aiohttp to make asynchronous requests and I want to test my code. I want to mock out requests sent by aiohttp.ClientSession. I am looking for something similar to the way responses handles mocking for the requests lib. How can I mock out…
mcranston18
  • 4,680
  • 3
  • 36
  • 37
25
votes
4 answers

How to retry async aiohttp requests depending on the status code

I am using an API and sometimes it returns some odd status codes which could be fixed by simply retrying the same request. I am using aiohttp to do submit requests to this api asynchronously. I am also using the backoff library to retry requests,…
Kay
  • 17,906
  • 63
  • 162
  • 270
25
votes
2 answers

AWS Fargate Task - awslogs driver - Intermittent Logs

I am running a one-off Fargate Task that runs a small python script. The Task Definition is configured to use awslogs to send logs to Cloudwatch but I am facing a very strange intermittent issue. Logs will sometimes appear in the newly created…
user10121455
25
votes
3 answers

How to reuse aiohttp ClientSession pool?

The docs say to reuse the ClientSession: Don’t create a session per request. Most likely you need a session per application which performs all requests altogether. A session contains a connection pool inside, connection reusage and keep-alives…
davidtgq
  • 3,780
  • 10
  • 43
  • 80
25
votes
3 answers

How to download images with aiohttp?

So I have a discord bot that I'm playing with to learn Python. I have a command that downloads images, and edits/merges them, then sends the edited image to chat. I was using requests to do this before, but I was told by one of the library devs for…
link2110
  • 471
  • 1
  • 4
  • 7
25
votes
1 answer

Asyncio and aiohttp route all urls paths to handler

I have trouble to find a wildcard url matching pattern which matches all incoming urls. This just matches a url which has nothing more than the hostname: import asyncio from aiohttp import web @asyncio.coroutine def handle(request): …
Jurudocs
  • 8,595
  • 19
  • 64
  • 88
24
votes
2 answers

how to setup a aiohttp https server and client?

I'm trying to learn how I might secure data from being altered after being passed over an open network between a server and a worker in my head I was thinking that it should follow something like: |server|---send_job----->|worker| | …
Mr. Buttons
  • 463
  • 1
  • 3
  • 9
23
votes
6 answers

aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host stackoverflow.com:443 ssl:default [Connect call failed ('151.101.193.69', 443)]

here is my code: import asyncio from aiohttp import ClientSession async def main(): url = "https://stackoverflow.com/" async with ClientSession() as session: async with session.get(url) as resp: …
0dminnimda
  • 1,242
  • 3
  • 12
  • 29
23
votes
1 answer

Fetching multiple urls with aiohttp in Python 3.5

Since Python 3.5 introduced async with the syntax recommended in the docs for aiohttp has changed. Now to get a single url they suggest: import aiohttp import asyncio async def fetch(session, url): with aiohttp.Timeout(10): async with…
Hans Schindler
  • 1,787
  • 4
  • 16
  • 25
23
votes
4 answers

aiohttp: Serve single static file

How to serve a single static file (instead of an entire directory) using aiohttp? Static file serving seems to be baked into the routing system with UrlDispatcher.add_static(), but this only serves entire directories. (I know that I eventually…
Niklas
  • 3,753
  • 4
  • 21
  • 29
22
votes
3 answers

Python package - aiohttp has a warning message "Unclosed client session"

My code is as follows: import asyncio import aiohttp urls = [ 'http://www.163.com/', 'http://www.sina.com.cn/', 'https://www.hupu.com/', 'http://www.csdn.net/' ] async def get_url_data(u): """ read url data :param u: …
Zhe Xiao
  • 454
  • 1
  • 3
  • 9
22
votes
2 answers

aiohttp.TCPConnector (with limit argument) vs asyncio.Semaphore for limiting the number of concurrent connections

I thought I'd like to learn the new python async await syntax and more specifically the asyncio module by making a simple script that allows you to download multiple resources at one. But now I'm stuck. While researching I came across two options to…
LLC
  • 223
  • 2
  • 7
22
votes
2 answers

aiohttp+sqlalchemy: Can't reconnect until invalid transaction is rolled back

I'm using aiohttp and sqlalchemy, and I've created a Singleton that helps me to connect when I'm needed a instance of SQLAlchemy (code follows). Unfortunately, every once in awhile I get the following error (which I "solve" by restarting the…
Yam Mesicka
  • 6,243
  • 7
  • 45
  • 64