Error: urllib.error.URLError:SSL

For a few days now, my app ( ) has stopped working in the cloud, although it continues to work locally without any issues.
The error occurs when reading an xls file with this command:
URL = “
df = pd.read_excel(URL, skiprows=3, engine=“xlrd”)

Can anyone help me?
Thank you very much.

In the past, this code solved a ssl error:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

urllib.error.URLError: <urlopen error [SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1129)>

urllib.error.URLError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).
File “/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/”, line 565, in _run_script
exec(code, module.dict)
File “/app/mapapreciocarburantes/”, line 127, in
df, prov_data, gdf, FAct = cargarFichero()
File “/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/”, line 186, in call
return self._get_or_create_cached_value(args, kwargs)
File “/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/”, line 211, in _get_or_create_cached_value
return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
File “/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/”, line 265, in _handle_cache_miss
computed_value = self._info.func(*func_args, **func_kwargs)
File “/app/mapapreciocarburantes/”, line 49, in cargarFichero
df = pd.read_excel(URL, skiprows=3, engine=“xlrd”)
File “/home/appuser/venv/lib/python3.9/site-packages/pandas/io/excel/”, line 478, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
File “/home/appuser/venv/lib/python3.9/site-packages/pandas/io/excel/”, line 1513, in init
self._reader = self._engines[engine](self._io, storage_options=storage_options)
File “/home/appuser/venv/lib/python3.9/site-packages/pandas/io/excel/”, line 35, in init
super().init(filepath_or_buffer, storage_options=storage_options)
File “/home/appuser/venv/lib/python3.9/site-packages/pandas/io/excel/”, line 530, in init
self.handles = get_handle(
File “/home/appuser/venv/lib/python3.9/site-packages/pandas/io/”, line 716, in get_handle
ioargs = _get_filepath_or_buffer(
File “/home/appuser/venv/lib/python3.9/site-packages/pandas/io/”, line 368, in _get_filepath_or_buffer
with urlopen(req_info) as req:
File “/home/appuser/venv/lib/python3.9/site-packages/pandas/io/”, line 270, in urlopen
return urllib.request.urlopen(*args, **kwargs)
File “/usr/local/lib/python3.9/urllib/”, line 214, in urlopen
return, data, timeout)
File “/usr/local/lib/python3.9/urllib/”, line 517, in open
response = self._open(req, data)
File “/usr/local/lib/python3.9/urllib/”, line 534, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File “/usr/local/lib/python3.9/urllib/”, line 494, in _call_chain
result = func(*args)
File “/usr/local/lib/python3.9/urllib/”, line 1389, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File “/usr/local/lib/python3.9/urllib/”, line 1349, in do_open
raise URLError(err)

I was able to get it by creating a custom requests session (using this method python - SSL error unsafe legacy renegotiation disabled - Stack Overflow), getting the url with that, and then passing the content into pandas.

import streamlit as st
import ssl
import urllib3
import requests
import pandas as pd
import io

class CustomHttpAdapter(requests.adapters.HTTPAdapter):
    # "Transport adapter" that allows us to use custom ssl_context.

    def __init__(self, ssl_context=None, **kwargs):
        self.ssl_context = ssl_context

    def init_poolmanager(self, connections, maxsize, block=False):
        self.poolmanager = urllib3.poolmanager.PoolManager(

def get_legacy_session():
    ctx = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
    ctx.options |= 0x4  # OP_LEGACY_SERVER_CONNECT
    session = requests.session()
    session.mount("https://", CustomHttpAdapter(ctx))
    return session

URL = ""
res = get_legacy_session().get(URL)
df = pd.read_excel(io.BytesIO(res.content), skiprows=3, engine="xlrd")

1 Like

This code solves the error, now my app works correctly. Thank you very much.
Best regards.

1 Like

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