0

I am trying to receive POST request Data with Flask but it is not giving me data into some variables.

Here is my Python code :

from flask import Flask, render_template, request, url_for

app = Flask(__name__)

@app.route('/hello', methods=['POST'])
def hello():
    request.get_data()
    a = request.data
    data = request.stream.read()
    print a,data
    return str(data)

if __name__ == '__main__':
  app.run('127.0.0.1')

With another Python File I am posting some data that file is

import requests
userdata={"abhi":"Great"}
resp = requests.post('http://127.0.0.1:5000/hello', params=userdata)
print resp

Runnig this file Output I am getting is

* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [29/Jun/2016 19:42:08] "POST /hello?abhi=Great HTTP/1.1" 200 -

I want this data. It is showing me in output but not printing that data.

So is there a way from which I can get that data into python.

Thanks in advance

Abhishek Parikh
  • 949
  • 1
  • 20
  • 41

0 Answers0