How To Only Send Certain Requests With Tor In Python?
right now i am using the following code to port my python through tor to send requests: socks.set_default_proxy(socks.SOCKS5, '127.0.0.1', 9450) socket.socket = socks.socksocket
Solution 1:
Instead of monkey patching sockets, you can use requests for just the Tor request.
import requests
import json
proxies = {
'http': 'socks5h://127.0.0.1:9050',
'https': 'socks5h://127.0.0.1:9050'
}
data = requests.get("http://example.com",proxies=proxies).text
Or if you must, save the socket.socket
class prior to changing it to the SOCKS socket so you can set it back when you're done using Tor.
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9450)
default_socket = socket.socket
socket.socket = socks.socksocket
# do stuff with Tor
socket.socket = default_socket
Post a Comment for "How To Only Send Certain Requests With Tor In Python?"