I got a local API that I want to test with very basic POST-requests. The PowerShell test-script works perfectly fine but the Python test-script (that should work the same way) does not.
PowerShell: api_post.ps1
$url = "http://test.local/"
$headers = @{"Content-Type" = "application/json"}
$payload = @(
@{
"Order_Number" = "123-vfs"
"SKU" = 123
"Company" = "Test Ltd"
}
)
$payload = ConvertTo-Json -InputObject $payload
# Works exactly as it should
Invoke-RestMethod -Uri $url -Method "POST" -Headers $headers -Body $payload
Python api_post.py
import json
import requests
URL = "http://test.local/"
HEADERS = {
"Content-Type": "application/json"
}
PAYLOAD = [
{
"Order_Number": "123-vfs",
"SKU": 123,
"Company": "Test Ltd",
}
]
# Returns an error
requests.post(URL, headers=HEADERS, data=json.dumps(PAYLOAD))
The returned error of the API is not meaningful since the API is still in the early testphase
P.S: I didn't tag PowerShell here since the PowerShell-example only shows that the POST generally works