erdiaker / torrequest

Simple Python interface for HTTP(s) requests over Tor
235 stars 42 forks source link

Request successful but it's still my IP #24

Open diamond-fish opened 1 year ago

diamond-fish commented 1 year ago

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 tor@default.service
* tor@default.service - Anonymizing overlay network for TCP
     Loaded: loaded (/lib/systemd/system/tor@default.service; 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/tor@default.service
             `-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
Aphexus commented 1 year ago

I have the same problem on windows. I installed Tor browser and tried to connect but it is not hiding. External connects does work in other external connections, just not torrequest.

Update:

I saw in another issue this solution which worked for me:

tr.session.proxies.update({ 'https': 'socks5h://localhost:9150', #assuming your local proxy port is 9050 'http': 'socks5h://localhost:9150', #assuming your local proxy port is 9050 })

(Not sure if the http is useful but I added it since I was using an http link to check the ip)