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

nginx, serve static files with authentication

I'm developping a web application with aiohttp where users authentication is implemented with aiohttp-security. I use nginx for the server deployement. The configuration is inspired by the aiohttp doc and looks like: location /api { …
David Froger
  • 645
  • 6
  • 15
9
votes
3 answers

How to prevent raise asyncio.TimeoutError and continue the loop

I'm using aiohttp with limited_as_completed method to speed up scrapping (around 100 million static website pages). However, the code stops after several minutes, and returns the TimeoutError. I tried several things, but still could not prevent the…
9
votes
2 answers

Session reusing in aiohhttp

I try to reuse HTTP-session as aiohttp docs advice Don’t create a session per request. Most likely you need a session per application which performs all requests altogether. But usual pattern which I use with requests lib doesn`t work: def…
Alex
  • 189
  • 1
  • 9
9
votes
2 answers

Async/IO and Parallelism

I am using aiohttp to create an Async/IO webserver. However, to my understanding, Async/IO means the server can only run on one processing core. Regular, synchronous servers like uwsgi, on the other hand, can fully utilize the computer's computing…
9
votes
1 answer

Is SQL injection protection built into SQLAlchemy's ORM or Core?

I'm developing an aiohttp server application, and I just saw that apparently it isn't able to use SQLAlchemy's ORM layer. So, I was wondering: if my application will only be able to use SQLAlchemy's core, is it still protected against SQL injection…
Sander Vanden Hautte
  • 2,138
  • 3
  • 22
  • 36
9
votes
1 answer

Why aiohttp deprecated the loop parameter in ClientSession?

In the aiohttp's doc reads: loop – event loop used for processing HTTP requests. If loop is None the constructor borrows it from connector if specified. asyncio.get_event_loop() is used for getting default event loop otherwise. Deprecated…
CSM
  • 147
  • 7
9
votes
3 answers

Class-based views in aiohttp

What is the right approach to use class-based handlers instead of functions in aiohttp library? I'm used to writing handlers as classes in Django so I am wondering how to do it correctly in aiohttp?
vwvolodya
  • 2,324
  • 2
  • 20
  • 30
9
votes
1 answer

Why am I getting a "Task was destroyed but it is pending" error in Python asyncio?

I use asyncio and beautiful aiohttp. The main idea is that I make request to server (it returns links) and then I want to download files from all links in parallel (something like in an example). Code: import aiohttp import…
Leon
  • 6,316
  • 19
  • 62
  • 97
8
votes
2 answers

How to speed up async requests in Python

I want to download/scrape 50 million log records from a site. Instead of downloading 50 million in one go, I was trying to download it in parts like 10 million at a time using the following code but it's only handling 20,000 at a time (more than…
Amit kumar
  • 151
  • 1
  • 4
  • 20
8
votes
0 answers

Automatically refresh auth token in aiohttp

I'm using aiohttp for a long-running process. At the beginning I authorize with the API get back an access token. The response also includes a refresh_token value (I think it's using oauth2). The process I'm running takes over an hour and the access…
Michael S.
  • 327
  • 1
  • 2
  • 11
8
votes
0 answers

Aiohttp how to log request body

I'm using aiohttp and want to log the raw request in ClientSession before it's sent. I saw that for requests module, it is doable: Python requests - print entire http request (raw)? But when I tried finding for aiohttp, I can only find for request…
phatasma-coder
  • 133
  • 1
  • 5
8
votes
1 answer

How to pass params and headers to aiohttp ClientSession

I wish to pass params and headers to aiohttp.ClientSession as shown here. This is what I have tried: async def make_request(self, url, headers, params): async with aiohttp.ClientSession(headers=headers, params=params) as session: …
Shery
  • 1,808
  • 5
  • 27
  • 51
8
votes
3 answers

Why aiohttp works slower than requests wrapped by run_in_executor?

all! I need to make about 10,000 requests to the web service, and i expected JSON in response. Since the requests are independent of each other, I want to run them in parallel. I think aiohttp can help me with that. I wrote the following…
8
votes
1 answer

Why asyncio.TimeoutError is raised?

I am doing request() of aiohttp.ClientSession instance and sometimes asyncio.TimeoutError is raised. I thought that aiohttp.ServerTimeoutError must be raised in this cases, which derived from asyncio.TimeoutError, as this doc says:…
sanyassh
  • 8,100
  • 13
  • 36
  • 70
8
votes
1 answer

Why doesn't asyncio always use executors?

I have to send a lot of HTTP requests, once all of them have returned, the program can continue. Sounds like a perfect match for asyncio. A bit naively, I wrapped my calls to requests in an async function and gave them to asyncio. This doesn't work.…
lhk
  • 27,458
  • 30
  • 122
  • 201