0

If a ' is used within the newName header value everything works okay, however, if is used, for example, the server fails to handle the request.

I'm debugging some larger code, but have created a minimalist version that is subject to the same problem.

from flask import Flask, request
app = Flask(__name__)

@app.route('/dave', methods=['POST'])
def hello():
    newName=request.headers['newName']
    return newName

if __name__ == '__main__':
    app.run(host= '0.0.0.0', debug=True)
    app.debug = True

I am using Postman to debug. If I send " David's " everything works as intended, however, if I send "David’s" it fails, and nothing seems to show up in the error log (although I may be missing a trick).

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
George
  • 183
  • 2
  • 10

1 Answers1

0

As pointed out in the comments I've neglected to realise that headers should not contain ’. Data should therefore be sent within the POST body, rather than the header.

Example: How to get data received in Flask request

Single quotes can be an issue with Python and JSON, apparently. This appears to solve that problem https://stackoverflow.com/a/36599122/5152133

George
  • 183
  • 2
  • 10