Forums

The different steps to run a python script using web.py ?

Hello,

On one of my webapps, I just want to run some standalone python script, i.e. that just execute some python, like scraping another website and then returns some raw values for consumption by the requestor.

So, I want to use web.py as it seems the most barebones approach which suits me fine.

First I set up the wsgi side of things as follows in /var/www/carbontracking_pythonanywhere_com_wsgi.py

import os
import sys

sys.path.append('/home/carbontracking/barebones_web')
from myapp import app
application = app.wsgifunc()

This access the file myapp.py which is in the /home/carbontracking/barebones_web folder

As per this page (https://webpy.org/) this myapp.py file contains the following

import web

urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:
    def GET(self, name):
        if not name:
            name = 'World'
        return 'Hello, ' + name + '!'

if __name__ == "__main__":
    app.run()

...... well I'll be hornswoggled, it's working now. I was just redoing all the steps carefully to try and find out why it wasn't working, and there it is, it works. I'm leaving this topic here as a testament to my incompetence.

P.S. The web.py module had to be installed as well with pip3 install --user web.py (I don't know why I have to use web.py instead of web)

Glad to hear that you made it work!