How do I use HTTPS proxy with aiohttp
in Python?
I have seen the docs where it is said I need to upgraded to HTTPS via the HTTP CONNECT method. But I have not found any complete Pythonic example how to do it? I have also viewed the questions Using https proxy with aiohttp and Does aiohttp support HTTPS proxies. They refer to the original documantation without details.
Let's suppose I have an HTTPS proxy with IP 1.2.3.4 and port 3128 and I want to request https://stackoverflow.com/ through it. How would the Python code (using asynchronous aiohttp
) for it look like?
I tried this with the error:
import asyncio
import aiohttp
async def main():
proxy = f"https://1.2.3.4:3128"
async with aiohttp.ClientSession() as session:
async with session.get("https://stackoverflow.com/", proxy=proxy) as response:
print(response)
asyncio.run(main())
The error:
ValueError: Only http proxies are supported