0

Really running out of steam trying to figure this puppy out

  • Using pyngrok = "^6.0.0"
  • Python 3.11.4

I've tried every version documented and simply can't get this to work I've gone back and forth between pyngrok and ngrok

def start_ngrok() : 
   from pyngrok.conf import PyngrokConfig
   from pyngrok import ngrok, conf


   conf.get_default().config_path = "settings/ngrok.yml"
   tunnel = ngrok.connect(name="app")
    
   #tunnel = ngrok.connect(addr="127.0.0.1:3000", proto="http", bind_tls=True)
   url = tunnel.public_url

my settings/ngrok.yml contains

region: us
version: '2'
authtoken: XXXXXX
api_key: XXXXXX
tunnels:
  app:
    addr: https://127.0.0.1:3000
    proto: http
    #bind_tls: true

I keep getting the following error ERR_NGROK_108

2023-08-23 15:57:40,310 - pyngrok.ngrok - INFO - Opening tunnel named: app
2023-08-23 15:57:40,310 - pyngrok.process - INFO - Starting ngrok with config file: settings/ngrok.yml
2023-08-23 15:57:40,313 - pyngrok.process - DEBUG - ngrok process starting with PID: 97578
2023-08-23 15:57:40,322 - pyngrok.process.ngrok - INFO - t=2023-08-23T15:57:40-0400 lvl=info msg="open config file" path=/Users/patrick/Projects/[XXXX]/settings/ngrok.yml err=nil
2023-08-23 15:57:40,323 - pyngrok.process.ngrok - WARNING - t=2023-08-23T15:57:40-0400 lvl=warn msg="can't bind default web address, trying alternatives" obj=web addr=127.0.0.1:4040
2023-08-23 15:57:40,323 - pyngrok.process.ngrok - INFO - t=2023-08-23T15:57:40-0400 lvl=info msg="starting web service" obj=web addr=127.0.0.1:4041 allow_hosts=[]

ERROR:  authentication failed: Your account is limited to 1 simultaneous ngrok agent session.
ERROR:  You can run multiple tunnels on a single agent session using a configuration file.
ERROR:  To learn more, see https://ngrok.com/docs/secure-tunnels/ngrok-agent/reference/config/
ERROR:  
ERROR:  Active ngrok agent sessions in region 'us':
ERROR:    - [XXXXX] ([XXXXX])
ERROR:  
ERROR:  ERR_NGROK_108
ERROR:  
2023-08-23 15:57:40,434 - pyngrok.process.ngrok - ERROR - t=2023-08-23T15:57:40-0400 lvl=eror msg="failed to reconnect session" obj=tunnels.session obj=csess id=[XXXX] err="authentication failed: Your account is limited to 1 simultaneous ngrok agent session.\nYou can run multiple tunnels on a single agent session using a configuration file.\nTo learn more, see https://ngrok.com/docs/secure-tunnels/ngrok-agent/reference/config/\n\nActive ngrok agent sessions in region 'us':\n  - [XXXXXX]
 ([XXXXX])\r\n\r\nERR_NGROK_108\r\n"

Checking the client api

$ ngrok --config settings/ngrok.yml api tunnel-sessions list
200 OK
{
  "next_page_uri": null,
  "tunnel_sessions": [],
  "uri": "https://api.ngrok.com/tunnel_sessions"
}

I've checked the ngrok dashboard no agents are running, no tunnels exist I can call the CLI just fine

16:18 $ which ngrok
/............/env/bin/ngrok

16:17 $ ngrok --config settings/ngrok.yml start app

Works fine, it's just using the while using connect it bombs out And I've run out of ideas

I've used all the connect methods listed in the pydocs

  • ngrok.connect(3000) # err_ngrok_3004 defaulted to connect to localhost vs 127.0.0.1 (os x quirk)
  • ngrok.connect('https://127.0.0.1') # agent issue ERR_NGROK_108
  • ngrok.werkzeug_develop() #err_ngrok_3004
pjaol
  • 173
  • 1
  • 5
  • Try some of these tips: 1. `print(ngrok.conf.DEFAULT_NGROK_PATH))` to find where `pyngrok` has installed `ngrok` for you, clobbert it, start over. Maybe somehow you're running an old `ngrok` 2.x binary (but the docs you're looking at are probably for 3.x) 2. Try not setting `config_path`. Then, set a `config_path` but comment all the configs out. Reintroduce then one-by-one (starting with `authtoken`) until you find the culprit. 3. [Follow the troubleshooting tips](https://pyngrok.readthedocs.io/en/latest/troubleshooting.html#test-in-the-python-console) for more log output. – alexdlaird Aug 23 '23 at 21:07
  • @alexdlaird I found the issue Flask auto reloader was restarting the app turning it to false causes it to run cleanly - is ngrok creating flies ? pids / state etc? app.run(debug=True, use_reloader=False, port=port, ssl_context=(cert, key)) – pjaol Aug 23 '23 at 21:58
  • Ah, that makes sense, yes. Because the auto-reloader starts two serves, hence the error saying you can’t have another tunnel open. If you had a paid account on `ngrok` my guess is it would work with true. – alexdlaird Aug 24 '23 at 15:12

0 Answers0