The requests
library in Python allows you to send HTTP requests and handle the responses easily. However, by default, it does not support SOCKS proxies. To make requests through a SOCKS5 proxy, you can use a library called requests-socks
.
First, you need to install the requests-socks
library using pip:
$ pip install requests-socks
Once installed, you can use the library to make requests through a SOCKS5 proxy. Here’s an example:
import requests
import requests_unixsocket
session = requests_unixsocket.Session()
session.proxies = {
'http': 'socks5://:',
'https': 'socks5://:'
}
response = session.get('http://example.com')
print(response.status_code)
In the above code, we first import the necessary libraries. We then create a session using the requests_unixsocket
library, which allows us to make requests over a SOCKS5 proxy. We set the proxy configuration in the session’s proxies
attribute, specifying the SOCKS5 proxy IP address and port. Next, we make a GET request to http://example.com
using the session. Finally, we print the response status code.
You can replace <proxy_ip_address>
and <proxy_port>
with the actual IP address and port of your SOCKS5 proxy server.