Search code examples
pythonpyngrok

How to Get ngrok https URL with pyngrok in Python


How would I write a Python program that automates ngrok connections? I've tried using pyngrok, but I want to display an https URL and it always returns http.


Solution

  • Per the pyngrok docs, two tunnels are opened by default, one http, one https. Just use bind_tls=True if you only want the https tunnel and it will be returned.

    from pyngrok import ngrok
    
    https_tunnel = ngrok.connect(bind_tls=True)
    

    If you want to know how pyngrok does this, its code is open source.