How can I run multiple ngrok sessions using pyngrok and a free account?

1k Views Asked by At

pyngrok multiple sessions setup

Hi, i'm trying to run 2 python files with pyngrok, but i receive next error:

The ngrok process errored on start: authentication failed: Your account is limited to 1 simultaneous ngrok agent session.
You can run multiple tunnels on a single agent session using a configuration file.
To learn more, see https://ngrok.com/docs/ngrok-agent/config/

i tried to change ngrok.yml file:

version: "2"
authtoken: *********
tunnels:
  first:
    addr: 8443
    proto: http    
  second:
    addr: 8444
    proto: http

And my .py files

1 file:

public_url = ngrok.connect(8443, "http").public_url

2 file

public_url = ngrok.connect(8444, "http").public_url

How to use multiple sessions with free acc and pyngrok?

2

There are 2 best solutions below

0
Justin Henning On

Make sure you are using the latest version of pyngrok that uses version 3.x of the ngrok Agent. The older version uses version 2.x of the ngrok Agent which starts both an http and https tunnels for the same endpoint by default. Defining two tunnels in the config file actually starts 4 tunnels. Version 3.x only starts the https tunnel by default.

0
BusinguZ On

To open multiply sessions with "PyNgrok" you need:

  1. Сhange the configuration file (which you already did)
  2. Write in the console ngrok ->ngrok start --all
  3. Run your web applications on these ports specified in the configuration without using PyNgrok. You just need to run localhost on the port and that's it. Next, ngrok will do everything himself.