Urequests- What am I doing wrong?
Posted: Sun Aug 14, 2022 3:48 am
Hello,
This won't work from my ESP-01S
I know I'm missing something- is the request malformed somehow?
I connect to the wifi- it gets and IP......
This works (test):
r = urequests.get("http://ip-api.com/json/")
print (r.text)
{"status":"success","country":"United States","countryCode":"US","region":"MI","regionName":","city":"and","zip":"","lat":11.11"lon":-81.3734,"timezone":"America/Newwork","is}}
But when try to open this URL (https://python.faith/dax/api4.php?Devices=2Relay) it blows up: (I'm passing data like I do from my pico- that code @ bottom)
r=urequests.get("https://python.faith/dax/api4.php?Devices=2Relay" )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/urequests.py", line 112, in get
File "/lib/urequests.py", line 60, in request
OSError: -40
But the actual page does respond to that URL in a browser:
// 20220813233731
// https://python.faith/dax/api4.php?Devices=2Relay
{
"Devices": "2Relay"
}
Its a very simple php page that looks for a get operation and then reply's back with json.
<?php
$Devices=$_GET['Devices'];
$APIOut = new stdClass();
$APIOut->Devices = $Devices;
$APIOutJSON = json_encode($APIOut);
echo $APIOutJSON;
?>
---------------------------------------------------------------------------------------------------------------
Code that works on my PICO (not ESP-01S): much more complex.... (Its a Get operation even though I named the php file posttest)
pushData="https://python.faith/dax/posttest.php?D ... _Humidity=" + str(dht11hum) + "&Sensor_Temp=" + str(tempfbmp280) + "&DateTime=12/27/2002&Sensor2_name=DHT22&Sensor2_Humidity=" + str(dht22hum) + "&Sensor2_Temp=" + str(dht22temp)
#print(pushData)
r = urequests.get(pushData)
This won't work from my ESP-01S
I know I'm missing something- is the request malformed somehow?
I connect to the wifi- it gets and IP......
This works (test):
r = urequests.get("http://ip-api.com/json/")
print (r.text)
{"status":"success","country":"United States","countryCode":"US","region":"MI","regionName":","city":"and","zip":"","lat":11.11"lon":-81.3734,"timezone":"America/Newwork","is}}
But when try to open this URL (https://python.faith/dax/api4.php?Devices=2Relay) it blows up: (I'm passing data like I do from my pico- that code @ bottom)
r=urequests.get("https://python.faith/dax/api4.php?Devices=2Relay" )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/urequests.py", line 112, in get
File "/lib/urequests.py", line 60, in request
OSError: -40
But the actual page does respond to that URL in a browser:
// 20220813233731
// https://python.faith/dax/api4.php?Devices=2Relay
{
"Devices": "2Relay"
}
Its a very simple php page that looks for a get operation and then reply's back with json.
<?php
$Devices=$_GET['Devices'];
$APIOut = new stdClass();
$APIOut->Devices = $Devices;
$APIOutJSON = json_encode($APIOut);
echo $APIOutJSON;
?>
---------------------------------------------------------------------------------------------------------------
Code that works on my PICO (not ESP-01S): much more complex.... (Its a Get operation even though I named the php file posttest)
pushData="https://python.faith/dax/posttest.php?D ... _Humidity=" + str(dht11hum) + "&Sensor_Temp=" + str(tempfbmp280) + "&DateTime=12/27/2002&Sensor2_name=DHT22&Sensor2_Humidity=" + str(dht22hum) + "&Sensor2_Temp=" + str(dht22temp)
#print(pushData)
r = urequests.get(pushData)