Python Flask application getting OPTIONS instead of POST

2024/10/11 23:18:43

I have a python Flask listener waiting on port 8080. I expect another process to make a series of POST's to this port.The code for listener is as follows.

#!/usr/bin/env python2
from __future__ import print_function
from flask import Flask, request
from werkzeug import secure_filename
from datetime import datetime
import os, traceback, sys 
import zlib
import ssl 
import json
import os
import base64app = Flask('__name__')@app.route('/',methods=['GET','POST','OPTIONS'])                                                                                                                                         
def recive_fe_events():try:data = request.get_data()if request.content_length < 20000 and request.content_length != 0:filename = 'out/{0}.json'.format(str(datetime.now()))with open(filename, 'w') as f:f.write(data)print('Wrote', filename)else:print("Request too long", request.content_length)content = '{{"status": 413, "content_length": {0}, "content": "{1}"}}'.format(request.content_length, data)return content, 413 except:traceback.print_exc()return None, status.HTTP_500_INTERNAL_SERVER_ERRORreturn '{"status": 200}\n'if __name__ == '__main__':app.run(host='0.0.0.0',debug=False,port=8080)

However whenever I try to trigger an event to be pushed to the above listener.It seems that I am getting OPTIONS instead of POST.

192.168.129.75 - - [20/May/2015 14:33:45] "OPTIONS / HTTP/1.1" 200 -
192.168.129.75 - - [20/May/2015 14:33:45] "OPTIONS / HTTP/1.1" 200 -
192.168.129.75 - - [20/May/2015 14:33:51] "OPTIONS / HTTP/1.1" 200 -
192.168.129.75 - - [20/May/2015 14:33:51] "OPTIONS / HTTP/1.1" 200 -

I read in the flask documentation. (Starting with Flask 0.6, OPTIONS is implicitly added and handled by the standard request handling.)

Why am I seeing OPTIONS when I expect POST.It seems that POST seems to be missing for some reason.I have captured the traffic while the POST is happening usuing tcpdump and analyzed using wireshark.The relevant portion of the trace is attached here. Wireshark decode output

It does seem to me that the source trying to do the POST is encrypting the data using SSL.Is my understanding correct?

Answer

Unless you are going to explicitly deal with the OPTIONS method, don't put it in your methods.

Try this instead:

@app.route('/',methods=['GET','POST'])
https://en.xdnf.cn/q/118265.html

Related Q&A

Raspberry pi:convert fisheye image to normal image using python

I have attached the USB webcam with raspberry pi to capture image and write code to send it using mail. It captures image using fswebcam commamnd so code for capture image in python script is :subproce…

modifying python daemon script, stop does not return OK (but does kill the process)

Following on from the previous post, the script now start and stops the python script (and only that particular script) correctly but does not report the OK back to the screen...USER="root" A…

fulfill an empty dataframe with common index values from another Daframe

I have a daframe with a series of period 1 month and frequency one second.The problem the time step between records is not always 1 second.time c1 c2 2013-01-01 00:00:01 5 3 2013-01-0…

How to mix numpy slices to list of indices?

I have a numpy.array, called grid, with shape:grid.shape = [N, M_1, M_2, ..., M_N]The values of N, M_1, M_2, ..., M_N are known only after initialization.For this example, lets say N=3 and M_1 = 20, M_…

Visualize strengths and weaknesses of a sample from pre-trained model

Lets say Im trying to predict an apartment price. So, I have a lot of labeled data, where on each apartment I have features that could affect the price like:city street floor year built socioeconomic s…

Scrapy get result in shell but not in script

one topic again ^^ Based on recommendations here, Ive implemented my bot the following and tested it all in shell :name_list = response.css("h2.label.title::text").extract()packaging_list = r…

How to find a source when a website uses javascript

What I want to achieve I am trying to scrape the website below using Beautiful-soup and when I load the page it does not give the table that shows various quotes. In my previous posts folks have helped…

How to print a list of dicts as an aligned table?

So after going through multiple questions regarding the alignment using format specifiers I still cant figure out why the numerical data gets printed to stdout in a wavy fashion.def create_data(soup_ob…

abstract classes in python: Enforcing type

My question is related to this question Is enforcing an abstract method implementation unpythonic? . I am using abstract classes in python but I realize that there is nothing that stops the user from …

Convert image array to original svs format

Im trying to apply a foreground extraction to a SVS image (Whole Slide Image) usign OpenSlide library.First, I converted my image to an array to work on my foreground extraction:image = np.asarray(oslI…