How To Entertain Anonymous Requests With Tor Requests & Python?

December 10, 2020
How to Entertain Anonymous Requests with TOR Requests & Python

TOR is extremely useful while you need to use python requests for without revealing the IP address, particularly when you do web scraping. This blog will utilize a wrapper for Python, which helps you similarly.

What is TOR?

What is TOR

To use TOR with Python, you will require two things

  • A software installed in the computer to use TOR
  • A network of different computers, which manages the TOR connections

In easy words, Python TOR web scraping helps you to track web traffic using numerous other computers with the intention that any third person won’t locate the traffic back to the user. Anybody who is trying to search the traffic might see random undetectable nodes about the TOR network.

How to Make Anonymous Requests using TOR Requests & Python?

Installing TOR

TOR request Python uses TOR as anaddiction. So, you need to Install the TOR first.

These instructions are given for Debian or Ubuntu users. For installation on Mac or Windows, check here.

sudo apt-get update
sudo apt-get install TOR

Restart this TOR service

sudo /etc/init.d/TOR restart

Configuring TOR

Let’s provide a new password to provide random access to a port through outside agents are prevented.

TOR --hash-password (enter your password here)

You will find a longer combination of numbers and alphabets as your newer hashed password. Then go to the TOR configuration file (TORrc) to do the necessary changes

Where a TORrc file is located depends on an operating system you are using as well as where you are getting TOR from. The scrape was at ./etc/TOR/TORrc and you can mentionthat to understand more.

We can do three things here:

  • Allow the “ControlPort” hearer for the TOR to listen port 9051 because it is a port for which TOR would listen for communications from applications chatting with a TOR controller.
  • Update a hashed password
  • Apply the cookie authentication

You can get this through uncommenting as well as editing the given lines just beyond the section of location unknown services.

SOCKSPort 9050 HashedControlPassword(your hashed password obtained earlier here)

CookieAuthentication 1

### This section is just for location-hidden services ###

Save this and exit to restart TOR.

sudo /etc/init.d/TOR restart

Now your TOR is ready! Kudos!

What is TOR Request?

TOR Request is the wrapper around the requests as well as stem libraries, which allows in making the requests using TOR request Python. You can go through the project.

It’s easy to install TOR request through PyPI:

pip install TOR request

You can try TOR Request and open the python terminal.

Using TOR request import the TOR Request

Then pass the password to TOR

tr=TORRequest(password='your_unhashed_password here')

You can also check the current IP address

import requests
response= requests.get('')
print ("My Original IP Address:",response.text)

Our response was

Our Original IP Address:

Let’s try itusing the TOR Request

tr.reset_identity() #Reset TOR
response= tr.get('')
print ("New Ip Address",response.text)

You would get a diverse IP address. Reset the TOR again for getting the newer IP address yet again.

Now it’s easy to mask IP address with Python through TOR requests.

That’s it from us!