API return JSON, generate a urequest error

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
VicLuna
Posts: 1
Joined: Fri Sep 13, 2019 8:36 pm

API return JSON, generate a urequest error

Post by VicLuna » Fri Sep 13, 2019 8:54 pm

Hi
I've created an Google API that returns a json like this:

jsonData= {"Celda1":"XX",
"Celda2":"123"
};
return return ContentService
.createTextOutput(JSON.stringify(jsonData))
.setMimeType(ContentService.MimeType.JSON);

the API is executed correctly. executing this code:

r=requests.post(url, json=str(payload), headers=headers)

But I got an error in my ES8266 like this

------------------------------------------------------------------
Traceback (most recent call last):
File "<stdin>", line 1, n request
File "urequests.py", line 97, in request
NotImplementedError: Redirects not yet supported

May you help me? I would appreciate so much

Vic.

User avatar
jimmo
Posts: 512
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: API return JSON, generate a urequest error

Post by jimmo » Sun Sep 15, 2019 12:20 pm

This means your service is returning a 302 (or 30x) redirect.

The fastest way to debug this would be to modify urequests.py and add print statements to show the headers and data returned from the server. In particular, on the line where it raises that error "Redirects not yet supported", add a print to show the value of the location header.

By the way, in urequests, you can post json generated from a Python dictionary using the `json` kwarg to request.

e.g.

Code: Select all

url = ...
headers = ...
jsonData= {"Celda1":"XX",
"Celda2":"123"
};
urequests.request(url, json=jsonData, headers=headers)

Post Reply