Reputation: 338
I can't understand the differance between new identity from Tor browser or python?
Python: I make request to call website from python with tor but website have limit reached and required reCAPTCHA so I make new identity to reset all informations to skip reCAPTCHA but doesn't work and IP is change success
Tor Browser: but the point here when I was used Tor Browser and Website show reCAPTCHA and I make new identity from Tor Browser is worked success and skip reCAPTCHA and website is working fine
from stem import Signal
from stem.control import Controller
import requests
proxies = {
'http': 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'
}
def new_identity():
with Controller.from_port(port = 9051) as controller:
controller.authenticate()
controller.signal(Signal.NEWNYM)
url = 'https://ifconfig.me/ip'
response = requests.get(url, proxies=proxies)
print('tor ip: {}'.format(response.text.strip()))
new_identity()
url = 'https://ifconfig.me/ip'
response = requests.get(url, proxies=proxies)
print('tor ip: {}'.format(response.text.strip()))
Upvotes: 2
Views: 1330
Reputation: 41
it' better :
def renew_connection():
with Controller.from_port(port=9051) as controller:
controller.authenticate(password='password')
controller.signal(Signal.NEWNYM)
controller.close()
def request_tor(url, headers):
renew_connection()
session = requests.session()
session.proxies = {}
session.proxies['http'] = 'socks5h://localhost:9050'
print((session.get(url)).text)
Upvotes: 1