Flask Timing Out
I'm getting the application failed to respond issue but on localhost it works fine.
180 Replies
Project ID:
N/A
You might find these helpful:
- Flask app crashing on dispaying image
- Mern App works locally, but not when deployed
⚠️ experimental feature
need more info
ok so basically it sends a request and gets the json from it and then returns it as a svg that uses the json
it works on localhost but it takes a second to load, it might be because Im literally doing it in flask
probably going to need to see some code, not much i can do just based on that
Its a lot
but this is the route
server invite link lmao
anyways
yea
😭
then it goes to a def render_presence(response)
and thats really big
137 lines long
how is this deployed? also how do you initialize your flask app
wdym how is it deployed?
I mean its through a github repo
initialize as in run?
yeah but like do you have a dockerfile, railway.json, etc
nah
yeah how do you configure it in main.py
also are there any logs when it fails to return a response
to run it
no
js this but it doesnt actually render it
does it sometimes take >60s to return a response?
i see 99.xxx and i suspect that might be return time in seconds
it doesnt even return it, it just loads until it times out
what
in the logs
yeah it takes more than 60 seconds to return a response in the logs I believe
But its quick on localhost
yeah so if it does that railway will drop the request essentially
oh ok, so what can I do to fix it
i'd first try adding some logging around
svg = render_presence(response)
, assuming that it actually runs and works fine there may be issues with returning a huge image in a response bodyok let me try
so I added some logging, well a lot but its timing out with cloudfalre
now also
nothing is being printed to console
@jackson
can someone help?
This server’s help is provided by the community, please be patient
go back to the basics, add a simple /health route and have it return a 200 code first
Before doing that I would check to see if your app is working with a Railway provided domain rather than a custom one
There can be a variety of issues with custom domains that aren’t related to your app’s code but the connection process
doesnt work with custom, or provided
mbmb
different routes work
Oh you’re the dark.bio guy, I remember checking out your site
wasn’t it working a couple days ago?
so rn the api itself works
so
https://presence.dark.bio/745421881594871939
but if you add /picture/{id}
then thats what breaks
it renders a svg
looks like this
hmm gotcha
where are you doing this rendering?
so I pass the response from the api to a def
like ths
none of the prints have been printing
it might be overloading or something
but.. it does seem to work on localhost
For one I see a hell of a lot of bad practice
But i’ll dig into it, what’s the repo link?
yeah I've never done this kinda shit
its private, I can invite you to it
Gotcha, my username is ItsGoldeneyes
ok, btw be ready that it is NOT built well
LMAO
Yeah no worries lol
chances are that’s probably the issue though
you want the repo link
Nah I got it from the email invite
oh btw some stuff might be extra weird because I used chatgpt to try and help make it faster
No worries, it's readable at least
LOL
What's an id I can use to test?
mine
745421881594871939
or if you want to use your own, you have to join the server
oh btw the constants is for the discord commands that are for something else, hence why they're commented out
I think the reason why it's not returning anything correctly may be because of all the try except checks you're doing
Those are really bad practice, I'll push a pr to correct that section of the code
ok, let me know
then how come its not even printing?
I'm only seeing one print statement
really??
holdon
under get_presence yes
oh
Oh whoops I was changing the wrong function lmao
oh.. is that where he meant logging
Lots of try except everywhere
I think they're only in the discord commands
theres none in the render_presence but theres 2 in the routes
3*
Pushed a commit that should help you out
Whoops meant to make a pr but I just merged into main
thats fine, lets see if it works
automatic server error
https://presence.dark.bio/picture/745421881594871939
ima look in the deploy logs
there are literally 0 logs
oh nvm
user not found
but im in that server..
nothing got returned in jsonify tho
pushed a commit to print the request so you can see what's in it
alr, so its because url.status_code != 200
thats whats happening
it has something to do with the api..
https://presence.dark.bio/745421881594871939
isnt returning anything
except return("user not found")
I haven't used the Discord api in a while, is the guild correct?
it cant find me in my own guild
tf
Maybe it should be a string instead of an int?
but its printing my guild name
what should
The guild id
thats how its supposed to be
because it does print my guild name
let me make it print the id
ok so the guild_id is right and it can find the guild but it doesnt seem to find the id
let me try making it int(user_id)
Oh yeah that's my mistake
ok so its supposed to be member = guild.get_member(int(user_id))
does it have to be an int?
yeah, doesn't seem to work if its not..
let me try str
It was str before
yea user not found
fr?
I pushed a fix
iht
ight
I think below it also has to be int
like where the picture route is
ha, works
I think
yeah add /picture
It's thinking
you can now see what I mean by loading for a long time 😭
ill lyk what logs appear
If it's going to take a while to render then your best option would be to rework it so that request is sent to another service that just renders the images
And have your current service display a "waiting for image" message until it recieves a response
hmm, what do you mean
so I could add the presence api to dark.bio and then make that entire application just be the image
idk if it would wrok though
so it cant find my id
so let me try sometihng
oh
its already int
weird..
btw it works on localhost
so
wait nvm, stopped working..
No, just make a third service that only processes render requests
what do you mean
When the user requests a /picture then they're given a screen that displays that the server is waiting for the render
idk im confused
Then once that request is finished the page is updated with the image that was created
how would this be
wdym
ok so the first service is the api
It would be a separate service that only creates the image
in a route?
the presence API sends a request to that service to create an image and the service returns that image when it's done processing
im sorry im kinda slow
ok
so
In the meantime the user is served a page that tells them that the rendering is in progress
yea
Once the rendering is done, the user is shown the image
sorry to chime in here, but how long does picture/<id> take to return when running this on your local machine?
when it works, maybe a second or two
im getting status 203
I mean
503
it took around 10 seconds to get user not found though
on my machine
What service is handling the user not found request?
/picture/<id> right
because thats where the print for the response is
that is getting hit
thats good though
Pretty sure you're getting rate limited
idk
By service I mean what's handling the presence.dark.bio/id call
Because that's what's returning 503
I feel so stupid
uhmm
It's all in the same service right? The only API you're reaching out to is the Discord API?
yes yes
Definitely think you're getting rate limited
actually no
At least with those 503s
I don't think I access the discord api at all..
You 100% do
well because I use stuff from discordpy
like the bot does it if yk what I mean
That's just a wrapper for the discord api
oh lmao
💀
so would a discord gateway better better?
No, you'll just have to wait a bit to do more testing
do you know the rate
nah I don't
just checked, and there's nothing wrong with API calls taking up to 5s
https://frantic-north-production-0ace.up.railway.app/wait/5s
so do yk wht the issue is
there are too many possibilities, if I were to debug id need the code
if you'd like I can add you to the repositry
sure
whats ur github
overrnet
added, also just be prepared that its not very... "good" code
alright ill see what i can do and get back to you, dinner is soon so be paitent please
yeah no problem, take your time
i have to install python first
oh lol
haven't done python in a while, but i used to do flask stuff all the time
this is a pretty cool little api, but theres room for improvement
for sure, like badges
how's it going? have you found out anything?
feel free to push a commit, its connected to the domain
yeah, your code as is, "/picture/<id>" doesn't work, but "/<id>" does like you said, but i did some things and now it does
i dont have git
oh lol
oh fr?
yeah, let me work some things out, and then ill give you a zip file for new code
sure
also, this is asking for a lot but if you can lmk what things could be faster, it would be great
yeah it could be written in Go lol
oh that’s a smart idea
idk go
im only partially joking, everyone is free to use whatever langue they like
for sure, but i’ve heard go is faster
easier than python 😉
sure
idk
i feel like python makes the most since tho yk
but sorry i dont know too much about optimising python code, all i can do is make things "work"
oh yeah np
so what was wrong with it
execution was hanging forever one that web request
url = requests.get(f"https://presence.dark.bio/{id}")
yea
as i thought from the very begining
hh
huh
but why would you want to make a loopback type request when the function that handles that request is sitting right above it
idk I was just trying to make it work lmao
just request the function directly
okay fair lol
hold on for a bit and let me get this sorted out
ok !!!! :))))))
try it locally
sus download fr
let me try this
rq
yeah ik, but i have no inclination to download the git cli or even use github to begin with
yea np
I was joking 😦
alright dinner, ttyl
ttyl
its so fastomg
Yeah it's faster when it doesn't have to make an http request to an old version of the API running on railway
oh.. thats interesting
Thanks for helping today!
no problem, happy coding!