I have two versions of the program:
- Synchronous, using
requests
library; - Asynchronous, using
aiohttp
library.
It is necessary to make requests to a site using SOCKS5 proxy. After installing the necessary libraries to work with SOCKS5 proxies, I tried making requests to a few sites. Everything worked fine with all sites except the necessary one. When sending a request to it, an error appeared:
0x05: Connection refused
I found the solution for the
requests
library in a couple minutes. But I didn't find a solution foraiohttp
, so it took me several hours to find a solution on my own.I finally found a solution, so I'm going to publish solutions for each of the libraries below to help other developers save time in solving the same problem.
To make a successful request to such a site try to enable reverse DNS (rDNS). I will describe how to do it for
requests
andaiohttp
libraries.requests
To enable rDNS, you need to use
socks5h://...
instead ofsocks5://...
in a proxy URL.requirements.txt
main.py
aiohttp
To enable rDNS, you need to pass the
rdns=True
parameter during initialization of theProxyConnector
.requirements.txt
main.py