Skip to content

Instantly share code, notes, and snippets.

@samlovescoding
Created May 31, 2020 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samlovescoding/a65d6385ef1460a7a4a0c8ab04479d8a to your computer and use it in GitHub Desktop.
Save samlovescoding/a65d6385ef1460a7a4a0c8ab04479d8a to your computer and use it in GitHub Desktop.
Request Session with Tor
import requests
from stem import Signal
from stem.control import Controller
def get_tor_session():
session = requests.session()
session.proxies = {'http': 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'}
return session
def renew_connection():
with Controller.from_port(port = 9051) as controller:
controller.authenticate(password="password")
controller.signal(Signal.NEWNYM)
renew_connection()
session = get_tor_session()
print(session.get("http://httpbin.org/ip").text)
print(requests.get("http://httpbin.org/ip").text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment