Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Luca Scutigliani

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TorRequest
A simple Python interface for HTTP(s) requests over
[Tor](https://www.torproject.org).
```python
from torrequest import TorRequest
from torrequest-reborn import TorRequest

with TorRequest() as tr:
response = tr.get('http://ipecho.net/plain')
Expand All @@ -19,19 +19,24 @@ You need Tor. It's available via Homebrew.
```sh
brew install tor
```
Or if you're on linux:
```sh
sudo apt update
sudo apt install tor
```

After installation, you may want to configure Tor by creating a `.torrc` file in your `$HOME` directory. More information is available on [Tor
documentation](https://www.torproject.org/docs/tor-manual.html.en).

## Installation
After installing dependencies, you can install `torrequest` via PyPI:
```sh
pip install torrequest
pip install torrequest-reborn
```

## Examples
```python
from torrequest import TorRequest
from torrequest-reborn import TorRequest

# Choose a proxy port, a control port, and a password.
# Defaults are 9050, 9051, and None respectively.
Expand Down Expand Up @@ -68,3 +73,6 @@ with TorRequest(proxy_port=9050, ctrl_port=9051, password=None) as tr:
## License
MIT

## Credits
Erdiaker - [Original torrequest repo](https://github.com/erdiaker/torrequest)

12 changes: 12 additions & 0 deletions torrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def __init__(self,
'https': 'socks5://localhost:%d' % self.proxy_port,
})

self.session.proxies.update({
'https': 'socks5h://localhost:%d' % self.proxy_port,
})

def _tor_process_exists(self):
try:
ctrl = Controller.from_port(port=self.ctrl_port)
Expand Down Expand Up @@ -60,7 +64,15 @@ def close(self):
def reset_identity_async(self):
self.ctrl.signal(stem.Signal.NEWNYM)

def _reset_session(self):
self.session = requests.Session()
self.session.proxies.update({
'http': 'socks5://localhost:%d' % self.proxy_port,
'https': 'socks5://localhost:%d' % self.proxy_port,
})

def reset_identity(self):
self._reset_session()
self.reset_identity_async()
time.sleep(self.ctrl.get_newnym_wait())

Expand Down