Hey! I recently tried using an API inside a streamlit app.
My only problem is that if I execute this API - as a standalone script (for example, from a jupyter notebook, or even a single python script.) then it works perfectly fine, without any issues, however if I call this api from a streamlit app - it returns an error.
The error is the following (returned by the api) :
’ Some internal processing error occurred. Please give us some time, we are looking into ’
I know it says it is an internal server error, but trust me, every single time i run it as a standalone script, it works fine. Except when i run it from a streamlit web app. Why does this happen ? How can I possibly fix it ?
here’s the code that calls the api:
def call_api():
import requests
import json
import streamlit as st
payload = { some parameters that arent relevant in any way}
print("executing....")
with open(filename, 'rb') as f:
r = requests.post('https://'api.endpoint...,
files={filename: f},
data=payload)
st.markdown("Executed!")
x = r.content.decode()
Does streamlit make some sort of a private environment that blocks communication from outside or what ? Its pretty annoying. This only happens if I’m using streamlit. Both python & streamlit are in the newest version
Hi, it does not matter what kind of api I use. So far anything i tried to run - which communicates with an outside endpoint - doesnt work.
However if this might help you then its just a OCR recognition api called SpaceOCR
I tried both and it doesn’t work in any of the cases. Also tried to run the streamlit code a different site hosting platform. It doesn’t work there either.
What happens if you remove the Streamlit pieces and just run the Python file?
def call_api():
import requests
import json
payload = { some parameters that arent relevant in any way}
print("executing....")
with open(filename, 'rb') as f:
r = requests.post('https://'api.endpoint...,
files={filename: f},
data=payload)
x = r.content.decode()
What type of error are you getting? When you change the API, what error do you get? I know you mentioned “Some internal processing error occurred. Please give us some time, we are looking into’”, but there should be an error code in addition to that, e.g. 400, 500, etc.
uh this is the output im getting (not sure which one is the error code):
{“OCRExitCode”:99,“IsErroredOnProcessing”
ErrorMessage":["E103: Some internal processing error occurred…
If you want I could give you the entire code (its barely 50 lines), but only in private - i really dont want to share it here
well yes - to explain it simply : i get a 200 response back all the time when there is no streamlit involved.
if there is a streamlit app running when i send the request i always get back this error.
I wonder if you tried passing an explicit User-Agent within the headers of your request? This is how you’re identified when throwing HTTP requests. I can’t see why the request within a Streamlit app wouldn’t work (as @Caroline mentions this is something a lot of users leverage) but you may try that:
Copy your user agent, e.g. visit this website. It should look something like this:
Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US);
Pass it to your requests.post() call by doing:
r = requests.post("htps://...", ..., headers={"User-Agent": "Mozilla/5.0..."})
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.