aiohttp

Testing aiohttp client with unittest.mock.patch

倾然丶 夕夏残阳落幕 提交于 2021-02-20 09:19:53
问题 I've written a simple HTTP client using aiohttp and I'm trying to test it by patching aiohttp.ClientSession and aiohttp.ClientResponse . However, it appears as though the unittest.mock.patch decorator is not respecting my asynchronous code. At a guess, I would say it's some kind of namespacing mismatch. Here's a minimal example: from aiohttp import ClientSession async def is_ok(url:str) -> bool: async with ClientSession() as session: async with session.request("GET", url) as response: return

Testing aiohttp client with unittest.mock.patch

天大地大妈咪最大 提交于 2021-02-20 09:18:29
问题 I've written a simple HTTP client using aiohttp and I'm trying to test it by patching aiohttp.ClientSession and aiohttp.ClientResponse . However, it appears as though the unittest.mock.patch decorator is not respecting my asynchronous code. At a guess, I would say it's some kind of namespacing mismatch. Here's a minimal example: from aiohttp import ClientSession async def is_ok(url:str) -> bool: async with ClientSession() as session: async with session.request("GET", url) as response: return

aiohttp - running client example “RuntimeError: SSL is not supported”

穿精又带淫゛_ 提交于 2021-02-11 12:36:15
问题 I'm just trying to go through the aiohttp examples but I get the error with the first one: import aiohttp import asyncio async def fetch(session, url): async with session.get(url) as response: return await response.text() async def main(): async with aiohttp.ClientSession() as session: html = await fetch(session, 'http://python.org') print(html) loop = asyncio.get_event_loop() loop.run_until_complete(main()) Running this gets me this: File "C:\ProgramData\Anaconda2\envs\asyncio\lib\site

aiohttp - running client example “RuntimeError: SSL is not supported”

☆樱花仙子☆ 提交于 2021-02-11 12:34:51
问题 I'm just trying to go through the aiohttp examples but I get the error with the first one: import aiohttp import asyncio async def fetch(session, url): async with session.get(url) as response: return await response.text() async def main(): async with aiohttp.ClientSession() as session: html = await fetch(session, 'http://python.org') print(html) loop = asyncio.get_event_loop() loop.run_until_complete(main()) Running this gets me this: File "C:\ProgramData\Anaconda2\envs\asyncio\lib\site

aioboto3 speedup not as expected

…衆ロ難τιáo~ 提交于 2021-02-10 17:59:50
问题 I'm trying the aioboto3 lib, which looks extremely promising for speeding certain tasks up. For example, I need to find tags for all S3 objects within a particular bucket and prefix. But unfortunately the speed increase is not what I had hoped for. With 1000 objects, it's about half the time. With 8000 objects, it was about the same time! This was run on a c3.8xlarge EC2 instance. Code: import asyncio import aioboto3 from boto3.dynamodb.conditions import Key import boto3 import logging import

Deploy aiohttp on heroku

心已入冬 提交于 2021-02-10 12:29:50
问题 I have built a simple web server on aiohttp and try to deploy it on heroku , but after deployment I get an error message: at=error code=H14 desc="No web processes running" dyno= connect= service= status=503 bytes= protocol=https project structure: ├── application.py ├── Procfile ├── requirements.txt ├── routes.py └── views ├── bot_team_oranizer.py ├── index.py └── __init__.py application.py from aiohttp import web from routes import setup_routes app = web.Application() setup_routes(app) web

embed a aiohttp server in a PyQt application

戏子无情 提交于 2021-02-05 08:08:47
问题 I am going to embed a aiohttp server in a PyQt application, but when I run the code below , the Qt window couldn't show, I know it was caused by web.run_app(app) , I've tried to move it into a thread , but then I got RuntimeError: There is no current event loop in thread 'Dummy-1' , so what should I do ? I've found asyncqt which might help ,but I don't know how to use it to deal with a aiohttp server. from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * from

RuntimeWarning: Enable tracemalloc to get the object allocation traceback with asyncio.sleep

主宰稳场 提交于 2021-02-04 12:08:17
问题 Trying to use a semaphore to control asynchronous requests to control the requests to my target host but I am getting the following error which I have assume means that my asycio.sleep() is not actually sleeping. How can I fix this? I want to add a delay to my requests for each URL targeted. Error: RuntimeWarning: coroutine 'sleep' was never awaited Coroutine created at (most recent call last) File "sephora_scraper.py", line 71, in <module> loop.run_until_complete(main()) File "/Library

RuntimeWarning: Enable tracemalloc to get the object allocation traceback with asyncio.sleep

三世轮回 提交于 2021-02-04 12:07:57
问题 Trying to use a semaphore to control asynchronous requests to control the requests to my target host but I am getting the following error which I have assume means that my asycio.sleep() is not actually sleeping. How can I fix this? I want to add a delay to my requests for each URL targeted. Error: RuntimeWarning: coroutine 'sleep' was never awaited Coroutine created at (most recent call last) File "sephora_scraper.py", line 71, in <module> loop.run_until_complete(main()) File "/Library