Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python handling Apache Request
#1
Hi,

A newbie to Python.

So basically, what I am trying to achieve here is, I have a web server (apache) on raspberry pi zero. Web pages has buttons and when the button are pressed a AJAX GET call is made to a XML file with parameters. Example - bcast.xml?mode=0 or bcast.xml?mode=1 or bcast.xml
Now there is no such file called bcast.xml
I am trying to develop an Python script which will be constantly looking for bcast.xml request from Apache and when the request is made, it performs some function and return data for that GET request.

I have no clue where to start and with some Googling and Stackoverflow, I was told to make use of Flask and WSGI and I made this

from flask import Flask, request
app = Flask(__name__)
@app.route("/bcast.xml", methods=["GET"])
def bcast():
    mode = request.args.get('mode',default = 0, type = int)
    print mode
app.run()
When executed, it says Server started in 127.0.0.1 with Port 5000
And when I load localhost and try clicking the buttons, the console say - 404 no file
Basically, the Python program should constantly look for that request and respond to it

How to do it, its a kind request. Please provide me directions or examples on how it has been done, as I am in a total lost here.
Also please let me know, what are the changes I should implement in Apache to make this work

Thanks in Advance
Reply
#2
http://flask.pocoo.org/docs/1.0/deploying/mod_wsgi/

1) You'll need to install the mod_wsgi module, so Apache knows how to communicate with python/flask.
2) You'll need to make a something.wsgi file, which will just be one line of code, and is used to let Apache know what callable object will handle requests (it's Flask's app, so there's nothing else you need to do here).
3) You need to edit the Apache config file so it knows which folder contains your wsgi program, and also what url(s) that app should be handling. The config file is probably in /etc, and it's probably named either http.conf or apache.conf or maybe httpd.conf.

But also, your file will never "look for" "bcast.xml". Apache will handle the url, since that's what servers do, and it'll run your url handler when that uri is requested.
Reply
#3
Thank you for that Nilamo

So, how can I handle bcast.xml request in Python, Is there anyway around it on how it can be done
Reply
#4
(Nov-15-2018, 10:36 PM)nilamo Wrote: http://flask.pocoo.org/docs/1.0/deploying/mod_wsgi/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Apache Module jfha73 2 460 Jan-26-2024, 07:59 PM
Last Post: noisefloor
Question Python request (post/get) Drunknmonkie 1 2,627 Jan-19-2023, 02:02 PM
Last Post: prvncpa
  Where is mod_wsgi for Apache on Windows? jfha73 0 1,612 May-01-2020, 02:21 PM
Last Post: jfha73
  Django deployment on apache server? tmmaersk 2 2,075 Mar-28-2020, 03:35 PM
Last Post: tmmaersk
  Enable error logging to browser for Python's Flask under Apache + mod_wsgi nikos 1 3,015 Sep-18-2018, 09:15 PM
Last Post: nikos
  Deploying SSL for my Django 2.0.1 server with Apache on Ubuntu 16.04 (droplet) Drone4four 2 9,031 Jan-26-2018, 06:44 AM
Last Post: Drone4four
  Low Level Request Handling c0da 11 8,108 Mar-15-2017, 03:58 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020