This answer is a summary of the comments (where a solution was found).
Have you tried typecasting address
and rgbImage
to String
before inserting?
Type invalidation is the root of many common bugs in DB operations.
There used to be a bug in Mongo back in 2013. The data would be inserted into the collection. But Mongo would not return a correct status response. That led to servers going 500
. Have you tried verifying if the data was indeed inserted into the collection?
Additionally run your flask app in debug=True
mode. That might give additional data.
Flask has very good debug traceback reporting support. This is generally a good idea. In fact this should be the first thing to do when encountering an error.
So this is weird, I turned on debug=True
and I get the following error: ValueError: View function did not return a response.
BUT the data did actually get sent to DB via homeReportsCollection.insert({'address':address, 'rgb':rgbImage})
line. I see it in my collection. How do I fix the error? Because the user is redirected to /recordReport
.
So the data was indeed inserted into the collection. It is possibly a Flask only issue. The traceback says it all. Flask requires that something is returned by a view method.
Try returning something in your function recordReport()
. Return anything you want. It could be an OK
message. It could be the _id
of the document you just inserted into the collection. Just don't return None
. Try this.
This behaviour is documented in this SO question.
Yeah, I returned an HTML template and no error now.
This is indeed the solution. Return something other than None
from your flask view methods. This also validates the behaviour observed by asker in the question:
Because if I replace that with return json.dumps({'status':'OK', 'address':'address', 'rgb':'rgbImage'})
, I can see the correct data in my browser.