http POST request returns 400 (bad request) #16376
Replies: 4 comments 1 reply
-
Today I added to the "headers"
See also an image of the jsonPayload as a json file. however the error 400 kept coming. |
Beta Was this translation helpful? Give feedback.
-
In my honest opinion, this discussion possibly didn't get reponses earlier because it sounds to me like a "google sheets" question more than a microypthon question. You're getting response text from google that's saying your request is somehow malformed. What |
Beta Was this translation helpful? Give feedback.
-
I don't know which requests library is being used. The board is flashed with a custom version of micropython by Pimoroni. The version is: "MicroPython feature/psram-and-wifi, pico_plus2_rp2350 v0.0.10 on 2024-11-18; Pimoroni Pico Plus 2 (PSRAM + LTE + WiFi) with RP2350. " I assume that Pimoroni used the latest version of micropython. In the Google Apps Script I use I added logging commands. The Logger.log command below prints the raw data received function doPost(e) { The Logger.log command resulted in following data the Google Apps Script is receiving:
|
Beta Was this translation helpful? Give feedback.
-
I don't know what Google app scripts are, though I'm presuming by the time data gets to it it's already gone through whatever layer of Google is returning the 400 to you. I think you need to try to send the same request raw post data your device actually sends via some other platform like curl or cpython / requests to see if you also get the 400 error there. The issue might be related to redirects or headers or whatever your google app script is returning? You might need to get some support from pimoroni to find it how to inspect the post data. The json payload doesn't really say much about the overall post request or whether the issue is related to the http client library in use or the Google API usage. |
Beta Was this translation helpful? Give feedback.
-
The goal of my project is to send to a Google Sheets spreadsheet the following data:
a value from a MCP9808 temperature sensor;
a datetime string;
a board ID.
To achieve this the MPY script sends a https POST request to a Google Apps Script.
I already did these kind of things for other types of boards and other programming environments (Arduino and Circuitpython).
Hardware used:
a Pimoroni PicoPlus2 (RP2350) microcontroller;
a Pimroni RM2 (WiFi/BLE) module;
an Adafruit MCP9808 temperature sensor.
The PicoPlus2 is flashed with Micropython (MicroPython feature/psram-and-wifi, pico_plus2_rp2350 v0.0.10 on 2024-11-18; Pimoroni Pico Plus 2 (PSRAM + LTE + WiFi) with RP2350).
The data the PicoPlus2 sends is accepted and handled by the Google Apps Script.
The data is arriving in the spreadsheet.
A Logger info writes to a Logger spreadsheet. The result is: "success", however the response to the post request, that the MPY script receives is: 400 (bad request).
I googled for similar cases but did not found any. I created a discussion post in the discussion page of Micropython.org on Github however no reply sofar.
The Google Apps script has been deployed and set for access to anyone. The apikey is limited for websites; with restrictions to spreadsheet where the data has to go; the Logger spreadsheet; https://script.google.com/home/projects/; https://script.google.com/macros/; https://www.googleapis.com/auth/spreadsheets/*
Question: anyone who can tell me what could cause the 400 response?
Below I will copy the most important lines related to the POST. I uploaded images of the spreadsheet and its content and of the hardware used: images.
Extract of the script, function
handle_request()
:I think the request is not
illegal
because it is accepted and handled by Google Apps.Question: anyone who can explain me where the request could be malformed?
Beta Was this translation helpful? Give feedback.
All reactions