GithubHelp home page GithubHelp logo

torrequest's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

torrequest's Issues

How to reset IP?

'tr.reset_identity' does not work. What exactly needs to be configured for it to work?

`from torrequest import TorRequest

with TorRequest(proxy_port=9050, ctrl_port=9051, password=None) as tr:
response = tr.get('http://ipecho.net/plain')
print(response.text) # not your IP address

tr.reset_identity()

response = tr.get('http://ipecho.net/plain')
print(response.text) # another IP address, not yours
input('')`

Request successful but it's still my IP

I'm trying to use this on my Raspberry Pi 3B. Followed instructions in the README and everything works, but it seems it's still using my real IP.

Code:

from torrequest import TorRequest

def main():
  with TorRequest(proxy_port=9050, ctrl_port=9051, password=<password>) as tor_request:
    response = tor_request.get('https://check.torproject.org/')
    print(response.text)

if __name__ == '__main__':
  main()

The response shows "Sorry. You are not using Tor."

The only settings I changed in /etc/tor/torrc was uncomment SocksPort to add my IP address and port 9050. The service status appears to be OK:

$ sudo systemctl status [email protected]
* [email protected] - Anonymizing overlay network for TCP
     Loaded: loaded (/lib/systemd/system/[email protected]; enabled-runtime; vendor preset: enabled)
     Active: active (running) since Mon 2023-08-28 16:59:59 PDT; 1min 46s ago
    Process: 6074 ExecStartPre=/usr/bin/install -Z -m 02755 -o debian-tor -g debian-tor -d /run/tor (code=exited, status=0/SUCCESS)
    Process: 6075 ExecStartPre=/usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0 --verify-config (code=exited, statu>
   Main PID: 6076 (tor)
      Tasks: 1 (limit: 1069)
        CPU: 5.856s
     CGroup: /system.slice/system-tor.slice/[email protected]
             `-6076 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0

Aug 28 17:00:00 pi Tor[6076]: Bootstrapped 5% (conn): Connecting to a relay
Aug 28 17:00:00 pi Tor[6076]: Opening Control listener on /run/tor/control
Aug 28 17:00:00 pi Tor[6076]: Opened Control listener connection (ready) on /run/tor/control
Aug 28 17:00:00 pi Tor[6076]: Bootstrapped 10% (conn_done): Connected to a relay
Aug 28 17:00:00 pi Tor[6076]: Bootstrapped 14% (handshake): Handshaking with a relay
Aug 28 17:00:01 pi Tor[6076]: Bootstrapped 15% (handshake_done): Handshake with a relay done
Aug 28 17:00:01 pi Tor[6076]: Bootstrapped 75% (enough_dirinfo): Loaded enough directory info to build circuits
Aug 28 17:00:01 pi Tor[6076]: Bootstrapped 90% (ap_handshake_done): Handshake finished with a relay to build circuits
Aug 28 17:00:01 pi Tor[6076]: Bootstrapped 95% (circuit_create): Establishing a Tor circuit
Aug 28 17:00:03 pi Tor[6076]: Bootstrapped 100% (done): Done

Cannot call TorRequest twice

When I run


from torrequest import TorRequest


with TorRequest() as tr:
    response = tr.get('http://ipecho.net/plain')
    print ("My Original IP Address:",response.text)

    tr.reset_identity() #Reset Tor
    response= tr.get('http://ipecho.net/plain')
    print ("New Ip Address",response.text)


with TorRequest() as tr:
    tr.reset_identity() #Reset Tor
    response = tr.get('http://ipecho.net/plain')
    print ("New Ip Address",response.text)

I get the following error:

Traceback (most recent call last):
  File "main.py", line 13, in <module>
    with TorRequest() as tr:
  File "/usr/local/lib/python2.7/dist-packages/torrequest.py", line 24, in __init__
    self.ctrl.authenticate(password=password)
  File "/usr/local/lib/python2.7/dist-packages/stem/control.py", line 1100, in authenticate
    stem.connection.authenticate(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/stem/connection.py", line 534, in authenticate
    raise AuthenticationFailure('socket connection failed (%s)' % exc)
stem.connection.AuthenticationFailure: socket connection failed ([Errno 111] Connection Refused)

This is similar if I call it twice in any way, such as a while loop, for a for loop (my intent is to repeat the tor request process an infinite amount of times, while resetting the ip). How do I fix this?

OSError: 'tor' isn't available on your system. Maybe it's not in your PATH?

from torrequest import TorRequest

with TorRequest() as tr:
response = tr.get('http://ipecho.net/plain')
print(response.text)

Traceback (most recent call last):

File "", line 4, in
with TorRequest() as tr:

File "C:\Users\anike\Anaconda3\lib\site-packages\torrequest.py", line 21, in init
self._tor_proc = self._launch_tor()

File "C:\Users\anike\Anaconda3\lib\site-packages\torrequest.py", line 46, in _launch_tor
take_ownership=True)

File "C:\Users\anike\Anaconda3\lib\site-packages\stem\process.py", line 285, in launch_tor_with_config
return launch_tor(tor_cmd, args, torrc_path, completion_percent, init_msg_handler, timeout, take_ownership)

File "C:\Users\anike\Anaconda3\lib\site-packages\stem\process.py", line 98, in launch_tor
raise OSError("'%s' isn't available on your system. Maybe it's not in your PATH?" % tor_cmd)

OSError: 'tor' isn't available on your system. Maybe it's not in your PATH?

release fix to https to PyPi

In torrequest==0.1.0 that's on PyPi, there's a bug that is fixed in the branch.
The key value in the proxy dictionary has a colon for https.
The key should be "https", but instead is currently is "https:"
Would you be able to release it to PyPi?

Random binding fails

Every n requests I get Process terminated: Failed to bind one of the listener ports. - what can I do?

`tr.reset_identity()` does not work properly

tr.reset_identity() does not seem to work properly. I'm using python 3.6 and Tor version 0.2.7.6 (git-605ae665009853bd).

Are there any additional settings that I may have to change in the Tor config or something? If so then that should be added to the readme

All HTTPS requests are sent outside Tor

Environment

OS: linux x86_64
Python: 3.9.4
OpenSSL: 1.1.1k

Python deps:

urllib3==1.26.4 
requests==2.25.1
torrequest==0.1.0 # (installed from pip)

Behavior

With plain (not https) connections:

>>> import requests
>>> import torrequest
>>> requests.get('http://ipecho.net/plain').text
192.0.2.102 # My real IP
>>> tr = torrequest.TorRequest()
>>> tr.get('http://ipecho.net/plain').text
203.0.113.75 # Someone else IP

With ssl connections

>>> import requests
>>> import torrequest
>>> requests.get('http://ipecho.net/plain').text
192.0.2.102 # My real IP
>>> tr = torrequest.TorRequest()
>>> tr.get('http://ipecho.net/plain').text
192.0.2.102 # My real IP!!!

Error in installation. Could not find the module named socksipyhandler

Here's the output

Collecting torrequests
Using cached https://files.pythonhosted.org/packages/b1/58/b736a9ba42381287dddda3c792985e0fb6020b7e26b69e96c17c100a35de/torrequests-1.1.10.zip
Collecting requests==2.13.0 (from torrequests)
Using cached https://files.pythonhosted.org/packages/7e/ac/a80ed043485a3764053f59ca92f809cc8a18344692817152b0e8bd3ca891/requests-2.13.0-py2.py3-none-any.whl
Collecting requesocks==0.10.8 (from torrequests)
Using cached https://files.pythonhosted.org/packages/2b/33/0ecebf3903181cd74d9ff885da4029f59e5f61c99dc66f39c5a170a66d27/requesocks-0.10.8.tar.gz
ERROR: Command errored out with exit status 1:
command: 'C:\Users\mumer\Anaconda3\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\mumer\AppData\Local\Temp\pip-install-gunnbal3\requesocks\setup.py'"'"'; file='"'"'C:\Users\mumer\AppData\Local\Temp\pip-install-gunnbal3\requesocks\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
cwd: C:\Users\mumer\AppData\Local\Temp\pip-install-gunnbal3\requesocks
Complete output (17 lines):
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\mumer\AppData\Local\Temp\pip-install-gunnbal3\requesocks\setup.py", line 6, in
import requesocks
File "C:\Users\mumer\AppData\Local\Temp\pip-install-gunnbal3\requesocks\requesocks_init_.py", line 26, in
from .models import Request, Response
File "C:\Users\mumer\AppData\Local\Temp\pip-install-gunnbal3\requesocks\requesocks\models.py", line 18, in
File "C:\Users\mumer\AppData\Local\Temp\pip-install-gunnbal3\requesocks\requesocks\packages_init_.py", line 3, in
from . import urllib3
File "C:\Users\mumer\AppData\Local\Temp\pip-install-gunnbal3\requesocks\requesocks\packages\urllib3_init_.py", line 16, in
from .connectionpool import (
File "C:\Users\mumer\AppData\Local\Temp\pip-install-gunnbal3\requesocks\requesocks\packages\urllib3\connectionpool.py", line 65, in
from .packages import socksipy
File "C:\Users\mumer\AppData\Local\Temp\pip-install-gunnbal3\requesocks\requesocks\packages\urllib3\packages\socksipy_init_.py", line 2, in
import socksipyhandler
ModuleNotFoundError: No module named 'socksipyhandler'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output

Error when executing torrequest with tor daemon running

Hi,

When I run:

from torrequest import TorRequest
tr=TorRequest(password='')

import requests
response= requests.get('http://ipecho.net/plain')
print ("My Original IP Address:",response.text)

tr.reset_identity() #Reset Tor
response= tr.get('http://ipecho.net/plain')
print ("New Ip Address",response.text)

I only succeed with the tor daemon stopped.

3

2

1

The error occurs when the tor daemon is running.

5

6

7

I ran the tests in a docker container, debian: sid.

12

I would like to be able to run torrequest with the tor daemon running, could someone help me with this problem?

Thanks!

How and where does it work?

Hi,

At this point I have tried about 20 different "acclaimed solutions" that all did not work. All on top was torpy, that seems to not be the actual tor but a little toy twin. The issue there was that due to insufficient amount of nodes in the toy twin network I had 99.9% of all times timeouterrors.

I do not know whether your solution works in windows but I am not willing to try it out before confirmation.
Could you please give sufficient details on how to install it on windows, mac, and linux, with as few dependencies as possible?
Imagine you want to explain to anyone's grandma via the internet how to install it, regardless of whether they read it now or in 10 years (which is how old some of the tutorials I searched through had been).

The next thing is then whether I can use it to replace socket.
Consider I have a program in which a client connects to a server via socket with

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((ip,port))

in order to send and recv bytes from that server via this socket. But the server shall not get to see the client's IP address or port. Can your package be used to replace those exact two lines suitably? (it does not have to be two lines in the solution.)

SocketClosed issue

I occasionally see this error in my logs even though the request completes:

 INFO - Error while receiving a control message (SocketClosed): received exception "read of closed file"

The calling code looks like this:

  with TorRequest() as tr:
    logger.debug("making request")
    response = tr.get(url)
    logger.debug("got response")
    # error happens here
    ...
  1. Is it better to have the tor daemon running rather than having it be invoked by the script?
  2. Certainly seems to be a benign issue and I suspect it's happening when the tor session is being torn down. How do I debug this issue or squelch this message?

I'd greatly appreciate any help or pointers! Thanks!

README examples broken in python 3.8

With the recent update to python 3.8, the examples on the README no loner work.

pipenv run python --version
Python 3.8.0
pipenv run python TorRequest-example-short.py
Traceback (most recent call last):
  File "TorRequest-example-short.py", line 3, in <module>
    with TorRequest() as tr:
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/torrequest.py", line 24, in __init__
    self.ctrl.authenticate(password=password)
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/stem/control.py", line 1100, in authenticate
    stem.connection.authenticate(self, *args, **kwargs)
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/stem/connection.py", line 592, in authenticate
    controller._post_authentication()
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/stem/control.py", line 3902, in _post_authentication
    owning_pid = self.get_conf('__OwningControllerProcess', None)
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/stem/control.py", line 2170, in get_conf
    entries = self.get_conf_map(param, default, multiple)
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/stem/control.py", line 2273, in get_conf_map
    for key in reply:
RuntimeError: dictionary keys changed during iteration

The longer example has an extra ' at the end of line 17 (look for data and auth). Once the syntax is corrected, here is the same error:

pipenv run python TorRequest-example-long.py
Traceback (most recent call last):
  File "TorRequest-example-long.py", line 9, in <module>
    with TorRequest(proxy_port=9050, ctrl_port=9051, password=None) as tr:
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/torrequest.py", line 24, in __init__
    self.ctrl.authenticate(password=password)
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/stem/control.py", line 1100, in authenticate
    stem.connection.authenticate(self, *args, **kwargs)
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/stem/connection.py", line 592, in authenticate
    controller._post_authentication()
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/stem/control.py", line 3902, in _post_authentication
    owning_pid = self.get_conf('__OwningControllerProcess', None)
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/stem/control.py", line 2170, in get_conf
    entries = self.get_conf_map(param, default, multiple)
  File "/home/user/.local/share/virtualenvs/gitlab-build-status-iwiHKajp/lib/python3.8/site-packages/stem/control.py", line 2273, in get_conf_map
    for key in reply:
RuntimeError: dictionary keys changed during iteration

OSError: Process terminated: Failed to bind one of the listener ports.

Hey,

I was looking at the package, and I tried the basic example:

from torrequest import TorRequest

with TorRequest() as tr:
    response = tr.get('http://ipecho.net/plain')
    print(response.text)  # not your IP address

I had a PATH issue but #2 solved that

but now I get this error:
raise OSError('Process terminated: %s' % last_problem)
OSError: Process terminated: Failed to bind one of the listener ports.

What can I do to fix this? I am using windows

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.