Python Flask应用程序获取选项而不是POST [英] Python Flask application getting OPTIONS instead of POST

查看:305
本文介绍了Python Flask应用程序获取选项而不是POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python Flask侦听器在端口8080上等待.我希望另一个进程对该端口进行一系列POST.侦听器的代码如下.

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 base64

app = 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_ERROR

    return '{"status": 200}\n'

if __name__ == '__main__':
    app.run(host='0.0.0.0',debug=False,port=8080)

但是,每当我尝试触发将事件推送到上面的侦听器时,似乎我得到的是OPTIONS而不是POST.

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 -

我阅读了烧瓶的文档. (从Flask 0.6开始,OPTIONS由标准请求处理隐式添加和处理.)

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

为什么我期望POST时会看到OPTIONS.似乎POST似乎由于某种原因而丢失了.我在使用tcpdump进行POST时捕获了流量,并使用wirehark进行了分析.迹线的一部分附在此处.

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.

在我看来,尝试执行POST的源正在使用SSL加密数据.我的理解正确吗?

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

推荐答案

除非您要显式处理OPTOINS方法,否则请勿将其放在您的方法中.

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

尝试以下方法:

@app.route('/',methods=['GET','POST'])

这篇关于Python Flask应用程序获取选项而不是POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆