title: stem.SocketError: [Errno 111] Connection refused
body: <p>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:</p>
  <blockquote>
  <p>stem.SocketError: [Errno 111] Connection refused</p>
  </blockquote>
  <p>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?</p>
  <p>Here is the code(This is the original from a tutorial (I have tried it without my own stuff.)):</p>
  <pre><code>from stem.control import Controller
  from flask import Flask
  
  if __name__ == &quot;__main__&quot;:
  
      app = Flask(&quot;example&quot;)
      port = 5000
      host = &quot;127.0.0.1&quot;
      hidden_svc_dir = &quot;c:/temp/&quot;
  
      @app.route('/')
      def index():
          return &quot;&lt;h1&gt;Tor works!&lt;/h1&gt;&quot;
      print (&quot; * Getting controller&quot;)
      controller = Controller.from_port(address=&quot;127.0.0.1&quot;, port=9151)
      try:
          controller.authenticate(password=&quot;my_password&quot;)
          controller.set_options([
              (&quot;HiddenServiceDir&quot;, hidden_svc_dir),
              (&quot;HiddenServicePort&quot;, &quot;80 %s:%s&quot; % (host, str(port)))
              ])
          svc_name = open(hidden_svc_dir + &quot;/hostname&quot;, &quot;r&quot;).read().strip()
          print (&quot; * Created host: %s&quot; % svc_name)
      except Exception as e:
          print (e)
      app.run()
  </code></pre>