简体   繁体   中英

Flask with Waitress - get request headers returns None

Using just the Flask server with Python, the following get request works:

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

class Result(Resource):
  def get(self):
    image_id = request.headers.get('image_id')

api.add_resource(Result, '/results')

if __name__ == '__main__':
  app.run(host='0.0.0.0', port=int(os.getenv('PORT', 5000)))

However, using Waitress, the following does not work (image_id is None):

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

class Result(Resource):
  def get(self):
    image_id = request.headers.get('image_id')

api.add_resource(Result, '/results')

if __name__ == '__main__':
  serve(app, host="0.0.0.0", port=int(os.getenv('PORT', 5000)))

POST and other GET requests work fine, it's just GET with headers that doesn't work. Anyone have any ideas?

I had the same issue, after searching around I found this issue on GitHub. Apparently it is a security feature and you should not use _ in your header. So you should rename your header to image-id or something else without a _ character for it to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM