Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call TorRequest twice #6

Open
ghost opened this issue Jun 16, 2019 · 1 comment
Open

Cannot call TorRequest twice #6

ghost opened this issue Jun 16, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 16, 2019

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?

@anasalzuvix
Copy link

anasalzuvix commented Aug 25, 2019

you need to setup Authentication to use torrequest to do this simply follow my command

sudo service tor start

tor --hash-password enter your password here

this command will genarate a password to replace this password you need to use this command

sudo nano /etc/tor/torrc

and find HashedControlPassword in torrc file and simply replace with the genarate hash password
You are almost done
now in your program simply define like this

with TorRequest(password='your_non_hash_password') as tr:

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant