Conversation
Edited 5 months ago

hmm okay so I almost have everything that I need in order to host #GAGSProject for everyone to use… except for one problem that I just can not figure out

for some reason if I try to use async #PRAW on PythonAnywhere, it fails with an error saying that it can’t connect to #reddit. but if I use regular PRAW, it works completely fine

on my own computer, both async PRAW and regular PRAW work and so does all of my GAGS code. so I have no idea what’s different about PythonAnywhere that’s causing this problem

unfortunately I basically have to use async PRAW in my code because the alternative would be that every single search would freeze my entire webapp for like 1-2 seconds, which would make it an unresponsive mess if more than one user was searching at a time

2
0
3

unfortunately I might have to make a post asking for help on r/redditdev and get condescended to by a bunch of highly intelligent redditors

0
0
2

@kasdeya quick Google search seems to say Python Anywhere has experimental support for ASGI async. I would consider re-architecting your app to run as WSGI (synchronous) instead. Ideally, you'd want an app that runs on the client and the client makes a request which updates the contents of the page based on the data the API responds with rather than providing a whole new page per request (which vaguely sounds like what's happening).
Also, WSGI can be scaled with multiple instances running. I don't know if Python Anywhere offers mutlithread WSGI (which is basically running mutliple instances of the app at once) but that would increase availability, if that is your concern. In either case, making so that the client fetches data to an API and updates it's contents based on the data provided would be the best way to overcome this problem. You may still have slow downs with responses to requests but at least you don't end up with like a 500 immediately or can implement a response when it's overloaded with requests

1
0
1

@shijikori omg thank you! you clearly know a lot more about WSGI than I do and you saved me a ton of trouble looking in the wrong direction (some kind of reddit API issue)

I have some authentication tokens from reddit that I’ve been using to make the API requests (otherwise I can’t see anything NSFW which is the whole point of my webapp lol) and I think I can change stuff around so that it will be safe to give all of that to the client (it will only get permissions to view posts but won’t be able to touch anything). unfortunately that means I’d have to learn how to do clientside rendering though :/ but I know I can figure it out eventually!

also multithreading sounds like an interesting option! I might look into that. although right now I’m using server-side caching of requests, so the threads would have to share that state somehow. do you know if that’s possible and what that would look like?

2
0
0

@shijikori actually nevermind about the multithreaded thing. I’m pretty sure that PythonAnywhere doesn’t have any support for that. thanks so much for the info though!

1
0
0

@kasdeya I don't know what Python Anywhere offers. You can run WSGI apps (such as a flask API) with gunicorn which supports multiple instances/threads.

0
0
1

@kasdeya multi threading for WSGI doesn't need to be implemented. It's just instantiating the code. The equivalent of running your script multiple times on the same machine but with a software that can spread requests between the different instances. Gunicorn is a software to run WSGI apps, production-ready.
Client-side rendering is very much JavaScript stuff and I have not done much of that. Your API has to provide the app for the client to run and then the client will poke your API because browsers tend not to like when client apps try to poke APIs from a different domain.

1
0
1

@kasdeya most my experience with that stuff comes from making a Discord API bot. Or Discord application bot. And I've worked a lot with REST APIs for a couple of years.

1
0
1

@shijikori gunicorn was a great recommendation! I got myself a VPS instead of messing with Python Anywhere any further, and I was able to get gunicorn set up incredibly quickly and easily. I still need to configure NGINX as its proxy (I guess because it provides security features that gunicorn doesn’t on its own?) but everything else is working perfectly

1
0
0

@kasdeya Am happy to hear my knowledge was useful! I don't know how NGINX works, if it can just run WSGI apps it's even easier but my guess is it could handle SSL certificates and all that in a more conventional, nicer, fashion.

1
0
1

@shijikori thank you! that’s exactly why I’m setting up NGINX actually. I guess the main purpose that NGINX serves is to protect gunicorn from slow loris attacks, and maybe other kinds of attacks too. but yeah apparently gunicorn needs NGINX between it and the open internet for various reasons

0
0
0