GithubHelp home page GithubHelp logo

rootdev4 / tor-request Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 5 KB

Tor proxy support for your python requests.

License: MIT License

Python 100.00%
python python3 tor requests proxy pysocks socket onion anonymization requests-module

tor-request's Introduction

Tor Request

Tor proxy support for python requests.

Dependencies

pip install pysocks
pip install requests

OR: pip install -r requirements.txt

Usage

# Import TorRequest class
from TorRequest import TorRequest

# Call TorRequest with path to Tor executable
t = TorRequest('<full_path_to>/tor.exe') # Windows
t = TorRequest('/usr/local/bin/tor') # Mac OS X (default path)
t = TorRequest('/usr/sbin/tor') # Linux (default path)

# Send optional, comma-separated HTTP headers
headers = {'User-Agent': 'Mozilla/5.0'}
t = TorRequest('<path>', headers)

# Get status (true: connected, false: not connected)
t.status()

# Get Tor ip address
t.ipAddr()

# Get requests session object with binded Tor circuit
t.session()

# Get website content with anonymized request
t.get('https://github.com/') # Returns HTML content
t.get('https://github.com/', True) # Returns response object (contains HTTP status code, text, ...)

# Example: print HTTP status code
print(t.get('https://github.com/', True).status_code)

# Send anonymized POST request to website (e.g. login credentials)
t.post('<url>', {'username': 'foo', 'password': 'bar'}) # Returns HTML content
t.post('<url>', {'username': 'foo', 'password': 'bar'}, True) # Returns response object

Tor executable

Windows

  • Download Tor Browser Bundle from the official website and install it
  • Tor executable is placed inside <tbb_installation_path>\Browser\TorBrowser\Tor\tor.exe
  • If you don't want to install the whole Tor Browser Bundle, you can also download just the Tor source code

Mac OS X

  • Install Tor using Homebrew via terminal: brew install tor
  • Find installation path: which tor
  • By default, installation path is /usr/local/bin/tor

Linux

  • Install Tor via terminal: apt install tor -y
  • Find installation path: which tor
  • By default, installation path is /usr/sbin/tor

Warning

For both Mac and Linux it's possible, to use that Tor executable that comes with the Tor Browser Bundle. I still recommend to use the Tor source code installed via terminal (for reason, see Troubleshooting section).

Troubleshooting

Exception "SyntaxError (unicode error)" thrown
Use forward slashes for path string or mark this string as raw string (e.g. r'C:\Users...\tor.exe'). You can also use double backslashes.

Error message "Missing dependencies for SOCKS support".
(Re-)install PySocks module.

Exception "SOCKSHTTPSConnectionPool" thrown.
This exception gets thrown, if you're using the Tor executable out of the Tor Browser Bundle in Linux while running the Browser itself. Use the Tor installation under /usr/sbin/tor to avoid this error.

tor-request's People

Contributors

rootdev4 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

jaimeudc570

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.