Send data requests http post. **SOLVED**
-
@bucknall @RadioTek @jmarcelino
Hello everyone,
I keep trying to send the requests but I still can not, I want you to see this that came out...
I do not know how to send requests, I even tried connecting the LoPy to the Raspberry through Tx and Rx but I also did not find positive result.
I really need help! Thank you...
-
@jmarcelino said in Send data requests http post.:
os.uname()
(sysname='LoPy', nodename='LoPy', release='1.6.10.b1', version='v1.8.6-556-g989d5ac9 on 2017-03-30', machine='LoPy with ESP32', lorawan='1.0.0'
Yes connection to my mobile network was via WIFI using phone as AP
My Laptop "as using now" is worked through my office WIFI network back in to ADSL2. DNS functioning of all computers on the network seems perfect.
Regards Alex
-
@RadioTek
Thank you for posting those. Just to be sure you're running the latest firmware on the LoPy?os.uname()
Also when you connected to the mobile network was that using a mobile phone as the WiFi AP?
-
@jmarcelino Hi ,
The result of print(wlan.ifconfig()) is ('10.1.1.37','255.255.255.0','10.1.1.1','8.8.4.4')
I have set the WIFI to a static address. I have tried 10.1.1.1, 8.8.8.8, 8.8.4.4, and
my providers DNS address, and all return the same result.
addr = socket.getaddrinfo('http://www.checkthat.com.au', 80)[0][-1]
print(addr) # returns ('200.249.64.63',80')
Then entering the known IP address for "www.checkthat.com.au"
addr = ('116.0.20.2',80)
print(addr) # returns ('116.0.20.2',80)
sa = socket.socket()
sa.connect(addr)
sa.send(b'GET / HTTP/1.1\r\nHost: checkthat.com.au\r\n\r\n')
data = sa.recv(1000)
sa.close()
print(data) # returns the header information of the pageI have tried this on my mobile network as well, with alternate IP address's
wlan.ifconfig(config=('192.168.43.10', '255.255.255.0', '192.168.43.1', '192.168.43.1')) and it has behaved exactly the same way.Thanks from Alex
-
@RadioTek
Can you post the result of
print(WLAN().ifconfig())
Also any chance you can try it on a completely different WiFi network? or maybe check the DNS result from another computer on the same network?
-
Digging deeper after much time, I find that,
addr = socket.getaddrinfo('www.google.com', 80)[0][-1]
print(addr)
always returns the the same ip address "200.249.64.63"
From lookup on the web this address appears to be registered in Brazil.
Does not matter what URL I use or what DNS address I set in the WIFI
configuration. I have a connection and this is what is returned as the
looked up IP
-
response = urequests.post("https://<url>", auth=("user", "pass"), headers={"Content-Type": "application/xxx+json", "Accept": "application/xxx+json"}, data='{"id": "%s"}' % myID)
The response will have several properties like response.text, response.status_code, ....
As you probably know you can list them via dir(response).It is not my library, I just modified it to make it work on my LoPy :)
-
@danielm Hi,
Do you have any examples of using your library?
-
Hi, try this urequests.py library, I modified it recently to make it work on LoPy with SSL. Unfortunately I did not comment my changes.
https://drive.google.com/file/d/0B2mvAuXuxQ6BOW5Sa210Wm9SWkk
-
I have been trying to do the same thing using urequest, and have been getting the same error message. Hours spent trying to get to the bottom of it.
-
Hi @scg94,
This appears to be a problem with their use of SSL within their library, I'm having a look at this and I'm getting the same issues. Let me see if I can fix their code!
I'll let you know soon what I discover!
Thanks,
Alex
-
you call request without specify method - first argument e.g. 'POST'it looks like not connected to network or host is really unavaiable - but
for test try get instead of post form some of this page - to get some contentsame as first
-
@livius Hi bro,
Yes, of course, it's connected...
-
@scg94
Is your board connceted to your router?
https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/wlan.html
-
@bucknall Hello Friend,
Thank you very much for your help, as I told you in the previous comment, I have tried different ways. What I want to do is send data, either by POST request or by MQTT to the Ubidots platform. I tried with both methods and the two libraries but I could not.
These are the urequest.py errors, I hope you can help me...
-
Hi @scg94,
Can you let me know the specific error that is coming up?
I've had some small issues with urequest.py in the past but should be easy to resolve them!
-
@bucknall
Hi good day,I have tried in all ways to make use of the library "urequest.py" but when sending the request I get a lot of errors...
dat={"temperatura_rpi": 100} header={"content-type":"application/json"} link="http://things.ubidots.com/api/v1.6/devices/raspberry-pi?token=xxxxxxxxxxxx" r = urequest.request(link,data=dat,headers=header)
This is one of many ways I have tried, in others I have put all the texts inside the "request" but also I get error ... I need urgent help please ...
Note: The LoPy reads the library without any problem, the error is in the sending of the request.
-
@scg94 You can use FTP (https://docs.pycom.io/pycom_esp32/pycom_esp32/toolsandfeatures.html?highlight=filezilla#pycom-filesystem) to connect to your board's filesystem.
If you drop the urequest.py file into the 'lib' folder ('flash/lib'), when you use the code:
import request
The library will be used in your project! :)
-
@bucknall Thanks!!! But, How Can I install the library??? Or, I only have to put the library in the project folder?
-
Hi @scg94
You could try using this library, urequest. It is very similar to the desktop Python version of request but is limited in some functionality.
https://github.com/micropython/micropython-lib/blob/master/urequests/urequests.py
Here is an example:
import request r = request.get("http://api.fixer.io/latest") print(r.text)