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 127.0.0.1:80: connect: connection refused

Versions:
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 (setup.py) … done
Building wheel for blinker (setup.py) … done
Building wheel for pathtools (setup.py) … 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 (setup.py) … done

%%writefile app.py
import streamlit as st
st.title(“hi”)

Writing app.py

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

NgrokTunnel: “http://67567754f01f.ngrok.io” → “localhost:80”
/usr/local/lib/python3.6/dist-packages/requests/init.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn’t match a supported version!
RequestsDependencyWarning)
t=2020-11-19T18:42:24+0000 lvl=warn msg=“failed to open private leg” id=61fef1ba5d31 privaddr=localhost:80 err=“dial tcp 127.0.0.1:80: 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 127.0.0.1:80: 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!

1 Like

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 app.py >/dev/null , and then wait a few seconds before opening the web app. Still curious what changed in the last few weeks!

4 Likes

Really helped a lot. Thank you

Hi,
I’m facing a similar problem
Can you please elaborate the solution that worked for you?

1 Like

Hi,
how to resolve the encountered error?
“The error encountered was: dial tcp 127.0.0.1:80: connect: connection refused

Hey guys,

If I follow the solution I always get:
2021-03-26 00:44:26.200 An update to the [server] config option section was detected. To have these changes be reflected, please restart streamlit. After that it seems the process is stuck and it’s just loading.

Why and how to fix that, any ideas?

1 Like

Have the same problem here

have the same problem:(