1

I want to update sqlite entry using put http method. When I send request via postman I get this error:

Method Not Allowed

The method is not allowed for the requested URL.

Here is my code:

@app.route('/api/users/<int:user_id>', methods=['PUT'])
def put_user(user_id):
    user = {
        'id': user_id,
        'login': request.json['login'],
        'password': request.json['password'],
    }
    cursor.execute('UPDATE USERS SET login=?, password=? WHERE id=?', (user['login'], user['password'], user['id']))
    connection.commit()
    return jsonify(user), 200

Here is request:

http://192.168.0.101:5000/api/users/4/

{   
    "id": 4,
    "login": "bbbb",
    "password": "aaaa"
}

http://192.168.0.101:5000/api/users/

[
     {
         "id": 1,
         "login": "123",
         "password": "1231231"
     },
     {
         "id": 2,
         "login": "login",
         "password": "sfsdfsd"
     },
     {
         "id": 3,
         "login": "4444",
         "password": "sass"
     },
     {
         "id": 4,
         "login": "ffff",
         "password": "aaaa"
     }
]
0

1 Answer 1

2

SOLUTION: I added key 'Accept' and value 'application/json' to headers tab in postman and it works!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.