What is python equivalent of php file_get_contents

2019-07-21 08:43发布

I am trying to get post request raw data in python, can anyone tell me how? OR the equivalence method of file_get_contents("php://input") in Python?

2条回答
三岁会撩人
2楼-- · 2019-07-21 09:14

To get a POST request's 'raw' data you do

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

body now contains the POST request body where the request parameters are typically stored. This is usually a key-value pair which can be translated into a python dictionary for you with json.loads(self.request.body)

查看更多
再贱就再见
3楼-- · 2019-07-21 09:17

webapp2 uses WebOb internally so you can access the request body via request.body. See http://docs.webob.org/en/latest/reference.html#request-body

查看更多
登录 后发表回答