Python HTTP Post是否被Cloud9阻止?

Python HTTP Post是否被Cloud9阻止?,python,flask,cloud9-ide,Python,Flask,Cloud9 Ide,我一直在Cloud9IDE上玩Python/Flask。到目前为止相当有趣。但当我尝试向测试项目添加http post时,Flask返回403或500。据我所知,当我附加数据或发送POST方法时,“request”对象是None。但这没有道理。这是非常直截了当的,就我所知应该是可行的。下面是python: from flask import Flask, jsonify, abort, request @app.route('/test', methods = ['POST']) def pos

我一直在Cloud9IDE上玩Python/Flask。到目前为止相当有趣。但当我尝试向测试项目添加http post时,Flask返回403或500。据我所知,当我附加数据或发送POST方法时,“request”对象是None。但这没有道理。这是非常直截了当的,就我所知应该是可行的。下面是python:

from flask import Flask, jsonify, abort, request
@app.route('/test', methods = ['POST'])
def post():
    print ('started')
    print request
    if request.method == 'POST':
        something = request.get_json()
        print something
烧瓶运行正常。我可以点击一个GET url,返回数据就可以了。我在“打印请求”上着陆时出错,因为请求为“无”


谢谢,

这里有两个问题:

  • 你有500个错误

  • “某物”总是没有

第一个问题是,您没有从路由函数返回任何内容

127.0.0.1 - - [15/Dec/2014 15:08:59] "POST /test HTTP/1.1" 500 -
Traceback (most recent call last):
  ...snip...
  ValueError: View function did not return a response
您可以通过在函数末尾添加return语句来解决这个问题。别忘了它必须是一根线

@app.route('/hi', methods = ['POST'])
def post():
    return "Hello, World!"
第二个问题不是看起来的那样。我怀疑对象不是None,但是返回字符串表示的函数返回None,所以打印的就是None。请尝试
打印类型(请求)
查看此操作

我认为您需要访问的是
表单
字段。下面是一个完整的示例:

from flask import Flask, request

app = Flask(__name__) 

@app.route('/test', methods = ['POST'])
def post():
    print type(request)
    if request.method == 'POST':
        print request.form
    return str(request.form)

app.run(debug=True)

您如何将数据附加到帖子?你能举个例子吗?我正在用邮递员来测试。我用表单数据和原始数据进行了尝试,但请求总是没有。这里的两个问题是“必须返回字符串”。我肯定有文件记录,但我就是没看到。还有response.get_json()什么也没做。但是,是的,我想看到的确实是我的要求。非常感谢!