Angel Chen
Angel Chen

Reputation: 67

Cannot Connect Links on Postman with Flask

I have 3 almost identical code simulating 3 crypto-miners, each run on a different port 5000, 5001 and 5002. The only difference is literally the last line of code:

app.run(host="0.0.0.0", port=5001)

I then connected them on postman with each other. However, the 5001 failed to connect to the other two every time. The other two works perfectly. enter image description here

The error msg looks like the following: enter image description here

This does not make sense to me since the python scripts and postman settings are symmetric and this 5001 failed every time. Restarting Postman and python did not help. Is it because postman has bandwidth issue? Thanks for any comments.

This is how I connected the nodes. Again it works for the other two scripts.

@app.route('/connect_node', methods = ['POST'])
def connect_node():
    json = request.get_json()
    nodes = json.get('nodes')
    if nodes is None:
        return "No node", 400
    for node in nodes:
        blockchain.add_node(node)
    response = {'message': 'All the nodes are now connected. The Mycoin     Blockchain now contains the following nodes:',
                'total_nodes': list(blockchain.nodes)}
    return jsonify(response), 201

When I try the debug mode, this is the log:

  File "D:\Dropbox\3350\homework\mini blockchain and crypto currency\MyCoin 
cryptocurrency\node2.py", line 161, in connect_node
    nodes = json.get('nodes')
AttributeError: 'NoneType' object has no attribute 'get'

A more detailed debug log here:

enter image description here

Upvotes: 0

Views: 436

Answers (1)

Adrian Krupa
Adrian Krupa

Reputation: 1937

Set JSON in Body.

bbb

bbb

It also sets Content-Type header to application/json.

Upvotes: 1

Related Questions