Using the following code, the server responds with a 301 redirect, but the client changes POST to GET, which is useless behavior because that GET endpoint does not exist. Using CURL -L -X POST works properly. This behavior is the same using python2 and python3 and on several versions of Raspbian.
>>> import requests
>>> url = "https://registry.micronets.in/mud/v1/register-
device/DAWG/AgoNDQcDDgg/aabbccddeeffgg"
>>> response = requests.post(url)
>>> response
<Response [404]>
# Server Log: (Note - both endpoints, are on the same server using virtual hosts)
redirecting to: https://hotdawg.micronets.in/registry/devices/register- device/AgoNDQcDDgg/aabbccddeeffgg
POST /registry/v1/register-device/DAWG/AgoNDQcDDgg/aabbccddeeffgg 301 16.563 ms - 122
{
"status": 404
}
GET /vendors//register-device/AgoNDQcDDgg/aabbccddeeffgg 404 0.604 ms - 14
# CURL version (succeeds)
curl -L -X POST "https://registry.micronets.in/mud/v1/register-
device/DAWG/AgoNDQcDDgg/aabbccddeeffgg"
Device registered (insert): {
"model": "AgoNDQcDDgg",
"pubkey": "aabbccddeeffgg",
"timestamp": "2019-12-27 15:44:14 UTC",
"_id": "HBlQzXfBnoB3N4fN"
}
# Server Log: (from CURL)
redirecting to: https://hotdawg.micronets.in/registry/devices/register-
device/AgoNDQcDDgg/aabbccddeeffgg
POST /registry/v1/register-device/DAWG/AgoNDQcDDgg/aabbccddeeffgg 301 0.364 ms - 122
POST /vendors//register-device/AgoNDQcDDgg/aabbccddeeffgg 200 1.745 ms - 157
I'd rather accept a better answer, but otherwise I plan to work around the problem as follows:
response = requests.post(url, allow_redirects=False)
if response.status_code == 301:
response = requests.post(response.headers['Location'])
response = requests.post(url, allow_redirects=False)
i=10
while i > 0 and response.status_code == 301:
response = requests.post(response.headers['Location'], allow_redirects=False)
i -= 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With