Response 400, test how it works with the transfer

Wolf F.K. on 10 Jul 2021 (Edited on 10 Jul 2021)
Latest activity Reply by Vinod on 12 Jul 2021

Hello to each other, I'm new here and wanted to test how it works with the transfer of data. To do this, I registered with ThingSpeak. I entered the API code in a Python script (see screenshot). Unfortunately, I always get the message: Response 400. When I enter the web address directly in the browser, I get a "0" back. I can't see an error entering the API key. Can you help me? I use a Raspberry 4B with the PIR sensor HC-SR501. The program will later run on a Raspberry Zero. Have a nice weekend everyone.

Christopher Stapels
Christopher Stapels on 12 Jul 2021

One thing to check is to be sure you are using the channel API key and not your user API key. Also you can check the format of the API call in your browser window. See the API keys tab of your channel view for the suggested format.

Wolf F.K.
Wolf F.K. on 12 Jul 2021

Danke für die schnelle Antwort. Ich habe einfach nochmal einen neuen API Schlüssel erzeugt und diesen per Drag and Trop eingegeben. Danach hat es funktioniert. Grüße aus Ulm/ Baden-Württemberg

Vinod
Vinod on 12 Jul 2021

I'd also recommend removing the extra spaces in your 'requests.get' statement. Specifically, the spaces in this snippet 'api_key = SOMETHING & field1 = SOMEVALUE' should be replaced with 'api_key=SOMETHING&field1=SOMEVALUE'. The spaces get encoded as %20 (ascii character for spaces) and could be the reason you're seeing the 400 response.