https://github.com/aio-libs The set of asyncio-based libraries built with high quality
popravich on travis_pypy
.travis.yml: chaching pip packa… Makefile: build/install only re… .travis.yml: cache redis-server… (compare)
import asyncio
import requests
import time
import json
import random
import aiohttp
from bs4 import BeautifulSoup
import logging
from ori_async import get_proxy
list_url = 'https://www.amazon.co.uk/s?k=dress&ref=nb_sb_noss'
product_url = 'https://www.amazon.co.uk/AUSELILY-Womens-Sleeve-Pleated-Pockets/dp/B082W811L3/ref=sr_1_1_sspa?dchild=1&keywords=dress&qid=1596264150&s=clothing&sr=1-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEzTEpRR0NLRlhQMFFDJmVuY3J5cHRlZElkPUEwMDY5Nzg5MkZTUllZWTM3VFVIQiZlbmNyeXB0ZWRBZElkPUEwOTU0NzQ1MTE0QzhFV0w0SjJOMCZ3aWRnZXROYW1lPXNwX2F0ZiZhY3Rpb249Y2xpY2tSZWRpcmVjdCZkb05vdExvZ0NsaWNrPXRydWU='
baidu_url = 'https://www.baidu.com'
with open('config.json', encoding='utf-8') as f:
data = json.load(f)
headers = data["headers"]
url = list_url
# proxies = get_proxy()
async def main():
connector = aiohttp.TCPConnector(ssl=False)
async with aiohttp.ClientSession(connector=connector) as session:
# proxy = proxies["http"]
# async with session.get(url, headers=data["headers"], proxy=proxy) as resp:
async with session.get(url, headers=data["headers"]) as resp:
print(resp.status)
content = await resp.text()
print(len(content))
start = time.time()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
end = time.time()
print('spend time is {}'.format(end - start))
# response = requests.get(url, headers=headers, proxies=proxies, timeout=8, verify=False)
response = requests.get(url, headers=headers, timeout=8, verify=False)
print("length is {}".format(len(response.text)))
ClientSession.request()
allows me to specify an SSL Context, but aiohttp.request()
does not? Conversely - aiohttp.request()
lets me specify a connector, but ClientSession.request()
does not - the connector is specified upon session creation. I want to issue a number of requests via different proxies, providing my own SSLContext. Is there a better way of doing that aside from the only solution I'm currently seeing, i.e. creating new ClientSessions with preconfigured connectors for every proxy?
Hello!
When I'm creating a server for websockets, I've done this in my view:
current_websocket = web.WebSocketResponse(
autoping=True, heartbeat=10
)
How ever, if the client disconnects without sending a close-code, the client don't ever seem to disconnect. Every time I then try to send a message to that client I get this warning:
INFO:aiohttp_chat.utils:> Sending message {'action': 'chat_message', 'message': '', 'user': 'jonas'} to user123
WARNING:asyncio:socket.send() raised exception.
(user123 is no longer connected)
I've checked these things on the websocket connection:
websocket.closed() # False
websocket.status # 101
websocket.exception() # None
How can I see if a connection has been broken abruptive, when heartbeat
don't seem to inform me in any way?
try: finally
around the entire async for message in current_websocket:
is the way to do it. :)
Hello, thanks for maintaining this great library
I'm experiencing a weird bug - after fulfilling 100 parallel requests, both aiohttp and httpx just halt - no further requests can be made.
I'm probably doing something stupid, can someone please tell me what's the right way to do this?
RuntimeError: Session is closed