Forums

Newbie Tips Please

Hi all,

I am probably asking for too much here without really having enough experience.

I have tinkered in HTML for a while and I am a Sysadmin by trade so I am fairly clued up with general IT. However, I have never looked into running Python webapps.

Can anyone point me in the right direction either with tips here or somewhere I could learn what I need to do.

I have a Python script on my PC (pokemon GO map) that when I call it from command line it starts a web server on localhost port 5000. I just access this from my webbrowser and I can port forward it to access it exteranlly if needed. Basically, the script talks to the webpage and refreshes it/updates the info it displays.

I want to upload the files onto my free PA account and run that same program with the webpage frontend. I have tried to create a web app but I'm not sure how I get my program to run and start the webserver (I think it's launching via flask but it is clashing with the webapps config).

I uploaded my python files and when I try to run the script from the bash console I get errors saying the host is in use etc (presumable because of the default Flask/Django webpage that is running on my webapp?).

Will this python program require some heavy editing to be able to get it running in a web app?

Thanks everyone!

Matt

Hi Matt,

The way web apps work on PythonAnywhere (and on hosting providers generally) is that you get multiple processes, each of which is running your web app. When you set up a site on the "Web" tab, what you're doing under the hood is setting up code that tells the PythonAnywhere system what code to run in each of those processes. Incoming requests to the web app are sent to the processes in an appropriate manner to balance load between them.

All this means that in your web app code on PythonAnywhere, you don't need to start your own web server. If you're using Flask, this means that you should not call the "app.run()" function. All of that is handled by PythonAnywhere.

Instead, just put the code somewhere, comment out the app.run() or otherwise disable it, then edit the WSGI file -- which is linked from the "Web" tab and is the one that connects up the web-hosting system with your code -- and make sure it does the appropriate stuff for Flask. There's some commented-out code in there that should work with pretty minor (and hopefully obvious) modifications.

Giles

Thanks Giles that was very helpful.

bmwmatt were you able to run pokemon go map?

I think the Pokemon Go guys banned a lot of cloud computing services like ours from accessing their servers -- see this Reddit post :-(