No JSON flask request

I am working on my first flash application (version 0.10.1), as well as my first Python application (version 3.5). One of its parts should work as follows:

  • Submit form
  • Run the Celery task (which causes some third-party API calls)
  • When the Celery task API API ends, send a JSON message to a different URL in the application
  • Get the JSON data and update the database record with it

Here's the relevant part of Celery’s task:

if not response['errors']: # response comes from the Salesforce API call
    # do something to notify that the task was finished successfully
    message = {'flask_id' : flask_id, 'sf_id' : response['id']}
    message = json.dumps(message)
    print('call endpoint now and update it')
    res = requests.post('http://0.0.0.0:5000/transaction_result/', json=message)

And here is the endpoint that it calls:

@app.route('/transaction_result/', methods=['POST'])
def transaction_result():
    result = jsonify(request.get_json(force=True))
    print(result.flask_id)
    return result.flask_id

For now, I'm just trying to get the data and print the identifier, and after that I will worry about the database.

The error I am getting is this: requests.exceptions.ConnectionError: None: Max retries exceeded with url: /transaction_result/ (Caused by None)

, JSON, Force = True , , , . CocoaRestClient Content-Type /json, .

, , .

+4
1

request.get_json(force=True) ( None, silent=True). jsonify JSON. str_val.flask_id. . jsonify result.flask_id result['flask_id'].

, :

@app.route('/transaction_result/', methods=['POST'])
def transaction_result():
    result = request.get_json()
    return result['flask_id']

, REST . . - . , . , , .

UPD: , IP- 0.0.0.0. .

+3

Source: https://habr.com/ru/post/1624471/


All Articles