Python Forum
Flask request object None
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask request object None
#1
I am trying to set up a simple Flash app to receive sensor data from a microcontroller.

Simplified code:

from flask import Flask, request, jsonify, abort, render_template

from LogFactory import log
from Database import Database
from ApiHandler import ApiHandler

app = Flask(__name__)
wsgi_app = app.wsgi_app

api = ApiHandler()

@app.route('/api/record', methods=['POST'])
def record_data():
    [b]log.info(request)[/b]
    return api.RecordSensorData(request)

if __name__ == '__main__':
    app.run('0.0.0.0', 5555, debug=True)
When I POST data to this endpoint with the Microcontroller on the same network it works fine and request.json contains the correct JSON structure. However when I connect the microcontroller through a WiFI extender I am getting some odd results, specifically request is None.

Output:
* Serving Flask app "IotServer" (lazy loading) * Environment: development * Debug mode: on 2021-03-11 12:17:28,047 - INFO - * Running on http://0.0.0.0:5555/ (Press CTRL+C to quit) 2021-03-11 12:17:28,047 - INFO - * Restarting with stat 2021-03-11 12:17:28,174 - WARNING - * Debugger is active! 2021-03-11 12:17:28,175 - INFO - * Debugger PIN: 108-630-478 2021-03-11 12:18:10,578 - INFO - <Request 'http://192.168.0.23:5555/api/record' [POST]> 2021-03-11 12:18:10,579 - INFO - API /api/record called 2021-03-11 12:18:10,579 - INFO - [b]None[/b] 2021-03-11 12:18:10,579 - ERROR - 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. 2021-03-11 12:18:10,580 - INFO - 192.168.0.154 - - [11/Mar/2021 12:18:10] "POST /api/record HTTP/1.1" 500 -
Is there any way of seeing the complete raw post before flask tries to process it? Or anyone have any idea why this could be?

Thanks.
Larz60+ write Mar-11-2021, 03:16 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Modify XML request on Flask with ElementTree Chris_SK 0 2,467 Oct-26-2020, 08:59 AM
Last Post: Chris_SK

Forum Jump:

User Panel Messages

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