How to incorporate multiple proxies and verifying certificates using aiohttp?

Viewed 125

Using the requests module, the following line of code works:

requests.get(url, proxies={'http': 'http://126.0.0.1:21000', 'https': 'http://126.0.0.1:21000'}, verify=r'C:\Users\Downloads\ca.crt'))

However, when trying to use this line of code for the aiohttp package, there is an issue with the proxy parameter since it seems to only allow a single URL:

ProxyConnector

class aiohttp.ProxyConnector(proxy, *, proxy_auth=None, conn_timeout=None, keepalive_timeout=30, limit=None, share_cookies=False, force_close=True, loop=None)

where proxy (str) – URL for proxy, e.g. "http://some.proxy.com".

Also that aiohttp doesn't support https in this post here

Using the aiohttp module, this is my current code without verifying the certificate since I am not quite sure how to do this using aiohttp:

results = []
conn = aiohttp.ProxyConnector(proxy='http://126.0.0.1:21000')
async def get_listing_reviews():
    async with aiohttp.ClientSession(connector=conn) as session:
        tasks = df['nid'].apply(lambda x: session.get('https://example.com/List?itemId=' + str(x)).to_list()
        responses = await asyncio.gather(*tasks)
        for response in responses:
            results.append(await response.json())
0 Answers
Related