When working with Python's popular requests library for making HTTP requests, you may occasionally run into an issue where calling requests.post() seems to send a GET request instead of the expected POST.
This can be frustrating, but there are a few common reasons why this happens:
Forgetting to Pass Data
One main reason
import requests
url = 'https://api.example.com/create_resource'
requests.post(url)
This will send a GET request since no request body data was specified. To fix, pass a
data = {'name': 'John Doe'}
requests.post(url, data=data)
Request is Redirected
Another possibility is the initial POST request you make is redirected by the server to a GET request unbeknownst to you. You can check the final request method in the response history:
print(response.history[0].request.method)
If it shows
Summary
In summary,
Checking the request history and response codes can help debug odd request behavior like this when using