2

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()))

Mahmoud Gad
  • 338
  • 3
  • 11

1 Answers1

1

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)
Lashgari
  • 41
  • 11
  • Could you help to make this answer more useful by clarifying on why this would fix the issue? – Simas Joneliunas Jul 12 '21 at 00:47
  • Each time you send a new request, the signal gives you a new ip and after every 4 seconds you can add a time.sleep(4) to have a new ip for each request and you can use the fake_useragent library to create fake agents for you randomly. @SimasJoneliunas – Lashgari Jul 12 '21 at 05:02