Streamlit with Colab and pyngrok - Failed to complete tunnel connection - version issue?

For educational use, I’m trying to run Streamlit apps within a Google Colab Jupyter notebook.*

Here is my setup. This worked consistently a few weeks ago.

Now, the app only loads correctly about 5% of the time. The other 95% I’m getting an error like this (I edited the links):

Failed to complete tunnel connection

The connection to 67567754f01f[dot]ngrok[dot]io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:80 .

Make sure that a web service is running on localhost:80 and that it is a valid address.

The error encountered was: dial tcp connect: connection refused

python 3.6.9
streamlit 0.71.0 (also tried a couple previous versions)
pyngrok 5.0.0 (also tried 4.2.2. This is a new major version - relevant?)
Firefox 82.0.3

Complete code and output:

!pip -q install streamlit
!pip -q install pyngrok

Building wheel for watchdog ( … done
Building wheel for blinker ( … done
Building wheel for pathtools ( … done
ERROR: requests 2.23.0 has requirement urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1, but you’ll have urllib3 1.26.2 which is incompatible.
ERROR: google-colab 1.0.0 has requirement ipykernel~=4.10, but you’ll have ipykernel 5.3.4 which is incompatible.
ERROR: datascience 0.10.6 has requirement folium==0.2.1, but you’ll have folium 0.8.3 which is incompatible.
Building wheel for pyngrok ( … done

import streamlit as st


from pyngrok import ngrok
public_url = ngrok.connect(port=‘80’)
print (public_url)
!streamlit run >/dev/null

NgrokTunnel: “” -> “localhost:80”
/usr/local/lib/python3.6/dist-packages/requests/ RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn’t match a supported version!
t=2020-11-19T18:42:24+0000 lvl=warn msg=“failed to open private leg” id=61fef1ba5d31 privaddr=localhost:80 err=“dial tcp connect: connection refused”
t=2020-11-19T18:42:24+0000 lvl=warn msg=“failed to open private leg” id=8da0b078aaa7 privaddr=localhost:80 err=“dial tcp connect: connection refused”

Any suggestions for fixes?

*Motivation: I’m using Colab so that I can share files and have students view and edit apps entirely in the browser, with no installation required. Frame challenges welcome if there’s a better way to achieve this!

I’d work on these errors first…if you have installation issues in your dependencies, the Streamlit app itself might not even launch.

Looks like those errors didn’t end up mattering - the solution was to specify the port with !streamlit run --server.port 80 >/dev/null , and then wait a few seconds before opening the web app. Still curious what changed in the last few weeks!

1 Like

Really helped a lot. Thank you