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

Aiohttp error "Connect call failed" for multiple async requests to localhost

I am new to aiohttp and was just testing some of it's functionality. So I created a simple client and server script to see how many requests the async code could handle but I'm running into an error. The server script is as follows: from aiohttp…
Brian
  • 431
  • 8
  • 18
8
votes
1 answer

Python 3.6: get JSON from aiohttp request

I have some application which uses aiohttp. I sent POST request into approptiate endpoint, e.g.: POST mysite.com/someendpoind/ with data similar to: {"param1": "value1", "param2": "value2", ..., "paramn": None} Then on backend side, I want to add…
smart
  • 1,975
  • 5
  • 26
  • 46
8
votes
1 answer

Python pytest cases for async and await method

I am trying to write pytest for the following async, await methods but I am getting nowhere. class UserDb(object): async def add_user_info(self,userInfo): return await self.post_route(route='users',json=userInfo) async def…
lanchana gupta
  • 330
  • 1
  • 3
  • 11
8
votes
1 answer

How to use pytest-aiohttp fixtures with scope session

I am trying to write tests for aiohttp application. I am using pytest-aiohttp plugin. My intention is to initialize and run the application once before first test execution and tear down after all tests finished. pytest-aiohttp fixtures like 'loop',…
Belerafon
  • 488
  • 4
  • 13
8
votes
1 answer

aiohttp - Set a cookie and then redirect the user

I am writing a web server using the python aiohttp library. How do I set a cookie and then redirect the user to another page in one response? It's possible to redirect the user with aiohttp.web.HTTPSeeOther, but I can't find a way to attach cookies…
DXsmiley
  • 529
  • 5
  • 17
8
votes
1 answer

How to run async process from handler in aiohttp

I'm trying to understand how to run an asynchronous process from coroutine handler within aioweb framework. Here is an example of code: def process(request): # this function can do some calc based on given request # e.g. fetch/process some…
Valentin
  • 1,492
  • 3
  • 18
  • 27
7
votes
1 answer

Python coverage for async methods

I use aiohttp, pytest and pytest-cov to get coverage of my code. I want to get better coverage< but now I am a little bit stuck, because event simple code does not show 100% cov. For example this piece of code: @session_decorator() async def…
Anton Pomieshchenko
  • 2,051
  • 2
  • 10
  • 24
7
votes
1 answer

Converting multidict to dict with duplicate keys values as a list

I'm using Aiohttp's implementation of multidict(). Take this: >>> d = MultiDict[('a', 1), ('b', 2), ('a', 3)]) >>> d I want to convert d to a regular dictionary where duplicate key values are appended into a…
Deik
  • 134
  • 9
7
votes
1 answer

"Exception Ignored: RuntimeError: Event loop is closed" when using pytest-asyncio and aiohttp

I'm writing python tests with pytest and have some async code I want to test so I installed the pytest-asyncio plugin. The async code uses aiohttp and running the tests I get the following warning/error/hint AFTER the test runs…
hadamard
  • 401
  • 4
  • 16
7
votes
1 answer

Is there an essential difference between await and async-with while doing request in aiohttp?

My question is about the right way of making response in aiohttp Official aiohttp documentation gives us the example of making an async query: session = aiohttp.ClientSession() async with session.get('http://httpbin.org/get') as resp: …
7
votes
2 answers

Exception event loop is closed with aiohttp and asyncio in python 3.8

I am using asyncio and aiohttp to make concurrent requests. I've recently upgraded Python to version 3.8.0 and I'm getting a RuntimeError: Event loop is closed after the program has run. import asyncio import aiohttp async def do_call(name,…
depken
  • 73
  • 1
  • 5
7
votes
0 answers

How to copy data from one s3 bucket to another using async io( fast manner) in python?

I want to do multiple copy objects from one s3 bucket to another in asynchronous manner and also I want to maintain there status. I have already tried using async and await on s3 boto3 library but they doing sequential copy. I have also tried using…
Pyjava
  • 157
  • 12
7
votes
2 answers

HEAD requests with aiohttp is dog slow

Given a list of 50k websites urls, I've been tasked to find out which of them are up/reachable. The idea is just to send a HEAD request to each URL and look at the status response. From what I hear an asynchronous approach is the way to go and for…
tsorn
  • 3,365
  • 1
  • 29
  • 48
7
votes
1 answer

How to properly use asyncio.FIRST_COMPLETED

The problem is that I keep getting RuntimeError: Event loop is closed error even when I use return_when=asyncio.FIRST_COMPLETED inside await asyncio.wait(). My code: async def task_manager(): tasks = [grab_proxy() for _ in range(10)] …
PATAPOsha
  • 372
  • 3
  • 18
7
votes
1 answer

integrating django with aiohttp/asyncio

I want to integate django with aiohttp/asyncio for asynchronous programming and for websockets handling. I know django has celery & django-channels to do asynchronous task and websocket server respectively but aiohttp is having both asynchronous…
john
  • 539
  • 2
  • 9
  • 24