Why is python-requests not working over Tor, but Curl does?

24 Views Asked by At

For some reason I'm not able to make http requests using python over Tor. The standard method I've used for several years (using python requests library) has suddenly stopped working for me, and I have no idea why. The puzzling part is the proxy is working perfectly fine when connecting using curl. Details given below:

Using Curl:

$ curl -x socks5://127.0.0.1:9050 -s https://check.torproject.org/api/ip
$ {**"IsTor":true**,"IP":"193.26.115.61"}

Using python requests (test_tor.py):

# pip install requests[socks]
# requests==2.31.0

import requests

proxy_url = 'socks5://127.0.0.1:9050'
proxies = {
  'http://': proxy_url,
  'https://': proxy_url
}
print(requests.get('https://check.torproject.org/api/ip', proxies=proxies).text)
$ python3 test_tor.py
$ {**"IsTor":false**,"IP":"78.15.120.54"}

As you can seee from the above, IsTor=False using python/requests, but IsTor=True using curl. Any ideas why?

0

There are 0 best solutions below