Streamlit app running can not show the webpage with message refused to connect

Hi Everyone I met the problem. I’ve built an app to collect some webpage and put it on my own webpage. but some website could not run properly, it have message “refused to connect.” but other webpage could open normally as picture attached

Below is the error message:

but other webpage could run normally:

python code:

import streamlit as st

def main():
    st.title("Collecting Webpage")

    # Embed a webpage using an iframe
    st.markdown('<iframe src="https://www.light*****.com/" width="600" height="400"></iframe>', unsafe_allow_html=True)
    st.markdown('<iframe src="https://pt-*****.com/" width="600" height="400"></iframe>', unsafe_allow_html=True)
    st.markdown('<iframe src="https://med****.com/" width="600" height="400"></iframe>', unsafe_allow_html=True)
    

if __name__ == "__main__":
    main()

I’m nubie on streamlit, My apologize for my silly question and Could anybody help my problem ?

Many thanks, John Paul

Hi @devilution1979

This is a totally valid question, I’d suggest to do a preliminary check if the URL works, and if it does then show the iframe of the webpage.

Here’s a code snippet that you can adapt

import requests

response = requests.get('https://api.github.com')

if response.status_code:
  print('It works!')
else:
  print('Sorry, it doesn\'t work!')

You can go ahead and replace the print() statements with your st.markdown() statements.

Hope this helps!

1 Like

Hi @dataprofessor thanks for the reply.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.