Bottom Page

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
Quote
#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.
Quote
#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
Quote
#4
(Nov-15-2018, 10:36 PM)nilamo Wrote: http://flask.pocoo.org/docs/1.0/deploying/mod_wsgi/
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Handle parameters in POST request for python webserver? JBristow1729 1 122 Jul-16-2019, 10:59 PM
Last Post: scidam
  Receiving Werkzeug. exception. Bad Request error when using GET with an endpoint robogeek 0 162 Jul-02-2019, 01:04 PM
Last Post: robogeek
  How to send unicode string encoded in utf-8 in http request in Python MaverinCode 0 803 Apr-25-2019, 05:25 PM
Last Post: MaverinCode
  Is it possible to perform a PUT request by passing a req body instead of an ID ary 0 251 Feb-20-2019, 05:55 AM
Last Post: ary
  Python + request from specific website - please help hoff1022 8 601 Feb-14-2019, 06:52 PM
Last Post: buran
  Flask rest api How to retrieve json request raysefo 4 835 Jan-20-2019, 06:46 PM
Last Post: raysefo
  XML handling Kultz 4 452 Dec-27-2018, 08:40 AM
Last Post: Kultz
  Flask redirect(request.url) returns None iFunKtion 1 2,317 Nov-27-2018, 10:50 PM
Last Post: nilamo
  requests - handling exceptions Truman 2 482 Nov-13-2018, 11:54 PM
Last Post: Truman
  Web App That Request Data from Another Web Site every 12-hours jomonetta 15 1,512 Sep-26-2018, 04:19 PM
Last Post: snippsat

Forum Jump:


Users browsing this thread: 1 Guest(s)