【问题标题】:What is python equivalent of php file_get_contents("php://input")什么是 php file_get_contents("php://input") 的 python 等价物
【发布时间】:2016-07-03 20:09:29
【问题描述】:

我正在尝试在 python 中获取发布请求的原始数据,谁能告诉我怎么做?或者Python中file_get_contents("php://input")的等价方法?

【问题讨论】:

  • 取决于您运行的服务器/后端等类型
  • 我将使用谷歌应用引擎上传我的应用程序
  • 什么框架? webapp2?
  • 是的,我正在使用 webapp2

标签: python-2.7 google-app-engine webapp2


【解决方案1】:

要获取 POST 请求的“原始”数据

class YourRequestHandler(webapp2.RequestHandler):
    def post(self):
        body = self.request.body

body 现在包含通常存储请求参数的 POST 请求正文。这通常是一个键值对,可以使用json.loads(self.request.body)为您翻译成python字典

【讨论】:

    【解决方案2】:

    webapp2 在内部使用WebOb,因此您可以通过request.body 访问请求正文。见http://docs.webob.org/en/latest/reference.html#request-body

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-27
      • 2010-09-23
      • 2018-10-24
      • 2017-12-22
      • 2021-11-29
      • 2017-06-13
      • 2019-04-04
      相关资源
      最近更新 更多