1

We have 1) script sends many dicts

my_data = ({'key1':['test1', 'test2', ['test3', 23]]})
r = requests.post('http://127.0.0.1:5000/', data = my_data)

2) server

@app.route('/', methods=['GET', 'POST'])
def server_main():
    data = request.form.to_dict(flat=False) #this works, but with some issues, if dict.values() has lists 
data = # your ideas?
bswan
  • 57
  • 5

1 Answers1

1

Forms don't handle lists well. Try using JSON instead

Requests sends data as json if you pass it as parameter "json" instead of "data":

my_data = ({'key1':['test1', 'test2', ['test3', 23]]})
r = requests.post('http://127.0.0.1:5000/', json = my_data)

Flask can parse JSON requests like this:

@app.route('/', methods=['POST'])
def server_main():
    data = request.get_json()
H4kor
  • 1,552
  • 10
  • 28
  • Thx, it works! But now I see code 400 Bad Request (Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)) – bswan Aug 19 '19 at 23:24