4

I want to make an anonymous web request using python 3.

I've tried few suggestions such as: Make requests using Python over Tor

I've managed to get a fake ip using this snippet:

Installation

pip install requests requests[socks]

Basic usage

import requests

def get_tor_session():
    session = requests.session()
    # Tor uses the 9050 port as the default socks port
    session.proxies = {'http':  'socks5://127.0.0.1:9150',
                       'https': 'socks5://127.0.0.1:9150'}
    return session

# Make a request through the Tor connection
# IP visible through Tor
session = get_tor_session()
print(session.get("http://httpbin.org/ip").text)
# Above should print an IP different than your public IP

# Following prints your normal public IP
print(requests.get("http://httpbin.org/ip").text)

But that works only on port 9150 and when the tor web browser works. I want to make a request without the tor browser, as i want to Dockerize the whole thing.

I've read about Socks5, and as you can see i've installed it, but when i make a request on port 9050 on the same snippet i get:

requests.exceptions.ConnectionError: SOCKSHTTPConnectionPool(host='httpbin.org', port=80): Max retries exceeded with url: /ip (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))

How can i solve it?

Thanks!

Gabboxl
  • 91
  • 3
  • 16
Chen
  • 73
  • 1
  • 8
  • You want to use the Tor expert bundle as shown here: https://stackoverflow.com/questions/38847434/get-requests-in-tor-network-without-installing-tor-browser-bundle/38856291#38856291 – drew010 Dec 05 '18 at 02:39

2 Answers2

1

10061 is 'connection refused'

That means there was nothing listening on that port you tried to connect to, no service is up and running (no open port) or firewall on target IP blocks it

you can test that port with telnet

telnet `IP` `PORT`

And also check this port issue on Windows: here

danielpopa
  • 810
  • 14
  • 27
  • 2
    Solved! The instructions in the link you gave didn't help. But I've figured that if i double click tor.exe it starts to listen.. Thanks! – Chen Dec 04 '18 at 15:48
  • No tor running means nothing on that port is listening (no open port) – danielpopa Dec 05 '18 at 05:38
0

I was also facing this issue, in my case my tor service was not running, actually I was using kalitorify which is a transparent proxy, and whenever I was using this I was not be able to use normal sites such as google search or similar, so to use these sites I was turning off my kalitorify service which also turns off your tor service

So if you're also using that then also check it once

Nikhil Bhardwaj
  • 562
  • 10
  • 18