I have a fully functional tor hidden service with his v3 url, created with stem and the controller class. The server is redirecting the traffic into a local tcp server running on port 5000 created with socket. But now I want to connect to this hidden service using python. So I tried socks with SOCKS5 proxies, no way of making it work. I also tried the torpy library with the example provided on the offical doc but, again, no way to make it works:

from torpy import TorClient

url = 'myv3torurl.onion'

tor = TorClient()
with tor.create_circuit() as circuit:
    print('circuit done')
    with circuit.create_stream(('http://' + url, 5000)) as client:
        client.send(b'yeah yeah im there')

Also tried changing the url adding http:// or https://, or tried to change the port with 80, 9050 or 9051. The torpy logs are always the same and you can find them here.

At this point I do not really know what to try. I just want a tcp connection hosted by the onion website. And by the way, I'm sure it's not a problem of the server because if I try to copy and paste the url on the tor browser it is fully reachable. Thank you for any help.

  • Does your hidden service run a web service? Are you able to connect using the Tor Browser? Can you connect to your hidden service outside of Python, for example with torsocks telnet foo.onion?
    – Steve
    Oct 9, 2020 at 4:18
  • my hidden service is supposed to redirect the traffic to my local-running tcp server. Exactly as a proxy. I'm able to connect with tor browser. Yes i can connect to it.
    – Gianla
    Oct 19, 2020 at 18:34
  • I had tried with the same library and found one thing, you can visit v2 hidden services using PyTor but not v3 address. You need to found 16 charachter of onion site instead of 56. put this url: "nzxj65x32vh2fkhk.onion" Hope you will get the answer. if any one can get the response from v3 please let me know how.
    – uknown_guy
    Apr 10, 2021 at 20:53
  • Do you mean TorPy or pytor? TorPy does not support v3 addresses, and pytor doesn't seem to be well supported. But if you have more questions, please make a new question since people will not see it when you post it as an answer on someone else's question.
    – Steve
    Apr 10, 2021 at 21:09

1 Answer 1



By the message in line 20 of the log:

20. Exception: Can't extend to hidden service

I think your tor daemon is not accepting connections coming to it. Did you created Hidden services in your torrc server machine?

Since I'm a new user and I need 50 messages to be able to post a comment, I will use this Answer field.

For every port you want your tor to accept, you need to create a hidden service. Add these lines to you torrc tor configuration file on the server that is hosting the tor daemon:

HiddenServiceDir C:\Tor\Data\Tor\os-ssh
HiddenServicePort 22

Change the path to adequate to your system, the ports to the ports you are currently using, and the name "os-ssh" to whatever you want. You can opt to maintain the prefix "os-" since I think it is the most default one.

Nevertheless to say, you can add several hidden services, just copy and past those two lines and edit as you wish.

If you are using the tor service as a proxy server, for others connect through it or even your application, you need to add:

SocksPolicy accept

Here change the ip to the ip of your computer that is running tor and change the default port from 9050 to 9100, to avoid conflicts, mainly if you also use Tor Browser (as I use). The SocksPolicy you can configure to accept all incoming connections from your local network trying to user this tor as a proxy server, instead of have to install the tor application on every computer. You can also change the ip to * (SocksPolicy accept *), meaning you will accept all incoming connections to serve as a proxy. You can also read more about the reject options, instead of accept.

Sorry by the awful text formatting, this is ones of my first posts here.

P.S. You can also create your application normally as you as working with ipv4 address, and using some proxy software like torsocks (linux) or Proxifier (windows). They you resolve the onions addresses, since they will use the proxy to resolve DNS(in Proxifier, if you check a box containing such option). Anyway, if you use linux, preffer seriously torsocks.

  • you absolutely hit the point. I want a proxy to my local-running tcp server. I'm on linux so do you still recommend torsocks? Also, how do i use it?
    – Gianla
    Oct 14, 2020 at 14:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .