【问题标题】:GAE - Can't obtain content in requestGAE - 无法获取请求中的内容
【发布时间】:2014-10-16 19:25:27
【问题描述】:

我正在使用带有 python 和 webapp2 的谷歌应用引擎。 (我是所有这些技术的新手) 我正在从客户端向服务器发送 JSON。

服务器:

class SetupAppHandler(webapp2.RequestHandler):
    def post(self):
        localdata = self.request.get('mydata')
        print("LocalData: " + localdata)

客户:

import requests,json

url = "http://localhost:8080/setupapp"
data = {'mydata': [14,17]}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url, data=json.dumps(data), headers=headers)

print(r.content)

localdata 似乎是空的。 我做错了什么?

【问题讨论】:

  • 在您的 post 处理程序中使用 json_data = self.request.body 来获取 json。 json 中的 mydata 键。数据 = json.loads(json_data) 本地数据 = 数据['mydata']

标签: python google-app-engine post http-post webapp2


【解决方案1】:

试试:

request.POST["mydata"]

对比:

request.get("mydata")

我相信甚至有一些 webapp2 中间件可以让你:

request.JSON['mydata']

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-29
  • 2015-03-30
  • 1970-01-01
  • 2019-02-15
  • 2013-02-20
相关资源
最近更新 更多