stem.SocketError: [Errno 111] Connection refused

2.2k Views Asked by At

I am trying to deploy a flask application as a .onion site. I am using stem. I have gone through a bunch of tutorials, but still, come up with this error:

stem.SocketError: [Errno 111] Connection refused

I have configured torrc, and I have changed the password for Tor Hidden Services. I have even tried adjusting the code order(to no avail.). Does anyone know what is wrong?

Here is the code(This is the original from a tutorial (I have tried it without my own stuff.)):

from stem.control import Controller
from flask import Flask

if __name__ == "__main__":

    app = Flask("example")
    port = 5000
    host = "127.0.0.1"
    hidden_svc_dir = "c:/temp/"

    @app.route('/')
    def index():
        return "<h1>Tor works!</h1>"
    print (" * Getting controller")
    controller = Controller.from_port(address="127.0.0.1", port=9151)
    try:
        controller.authenticate(password="my_password")
        controller.set_options([
            ("HiddenServiceDir", hidden_svc_dir),
            ("HiddenServicePort", "80 %s:%s" % (host, str(port)))
            ])
        svc_name = open(hidden_svc_dir + "/hostname", "r").read().strip()
        print (" * Created host: %s" % svc_name)
    except Exception as e:
        print (e)
    app.run()
1

There are 1 best solutions below

1
On

You are using two different ports. Getting controller from 9151 and then later setting options for 5000. Try using same port in both places.