diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..924437a --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md index b0c2d8e..a082ee3 100644 --- a/README.md +++ b/README.md @@ -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') @@ -19,6 +19,11 @@ 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). @@ -26,12 +31,12 @@ 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. @@ -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) + diff --git a/torrequest.py b/torrequest.py index eab1a2d..a4f68b2 100644 --- a/torrequest.py +++ b/torrequest.py @@ -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) @@ -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())