http post requests
-
help me to use the urequests module of github to send data (post http) json to my django app i can't solve it ...
-
@oglucio it would probably help if you told us what you did (including the relevant code), what you expect, and what actually happens (including any error messages, output, traces and logs...).
-
@jcaron this is my main.py code:
from network import WLAN
from pytrack import Pytrack
import urequests as requests
from L76GNSS import L76GNSS
import socket
import ujson
import json
import time
import pycom
import machineprint('hello')
py = Pytrack()
gps = L76GNSS(py, timeout=60)
DELAY = 60
WIFI_SSID = '*********'
wlan=WLAN(mode=WLAN.STA)
nets=wlan.scan()for net in nets:
if net.ssid == WIFI_SSID:
print('Network found!')
wlan.connect(net.ssid,auth=(WLAN.WPA2_ENT,'bbbbbbb','yyyyyy'),identity='sccccccc',timeout=5000)
print('Connecting...')
while not wlan.isconnected():
machine.idle() # save power while waiting
print('WLAN connection succeeded!')
print(wlan.ifconfig())
breakPost an Event to the Wia cloud
Post an Event to the Wia cloud
def post_location(latitude, longitude):
try:url = "https://mydjangoappdeployed" headers = {"Authorization": "Bearer ","Content-Type": "application/json"} json_data = {"latitude": str(latitude), "longitude": str(longitude)} print('try') if json_data is not None: req = requests.post(url=url,json=json_data) if req.status_code is not 200: machine.reset() else: print(json_data) return req.json() else: pass except: passlat = 53
lng = -6main loop
while True:
# Get coordinates from pytrack
coord = gps.coordinates(debug=True)
if not coord == (None, None):lat, lng = coord post_location(lat, lng) time.sleep(2) -
@jcaronI try to monitoring embedded robot with a pytrack board incorporate using his GPS data that I have to post to my Django app to make a filter.
-
@oglucio Can you please edit your post and add ``` alone on a line before and after your code so it's properly formatted?
Also, you haven't stated what you expect the code to do, and what it actually does, including error messages, logs, traces, etc.
-
'''
#Libraryfrom network import WLAN
from pytrack import Pytrack
import urequests as requests
from L76GNSS import L76GNSS
import socket
import json
import time
import pycom
import machinepy = Pytrack()
gps = L76GNSS(py, timeout=60)
DELAY = 60
#connection Wifi_enterprise
WIFI_SSID = 'hhhhhhh'
wlan=WLAN(mode=WLAN.STA)
nets=wlan.scan()for net in nets:
if net.ssid == WIFI_SSID:
print('Network found!')
wlan.connect(net.ssid,auth=(WLAN.WPA2_ENT,'ssssss','3333333'),identity='sssssss',timeout=5000)
print('Connecting...')
while not wlan.isconnected():
machine.idle() # save power while waiting
print('WLAN connection succeeded!')
print(wlan.ifconfig())
breakPost
def post_location(latitude, longitude):
try:url = "https://ggggggggr/api/1.0/" headers = {"Authorization": "Bearer ","Content-Type": "application/json"} json_data = {"latitude": str(latitude), "longitude": str(longitude)} if json_data is not None: req = requests.post(url=url,json=json_data) if req.status_code is not 200: machine.reset() else: print(json_data) return req.json() else: pass except: passlat = 53
lng = -6main loop
while True:
# Get coordinates from pytrack
coord = gps.coordinates(debug=True)
if not coord == (None, None):lat, lng = coord post_location(lat, lng) time.sleep(2)'''
-
@jcaron i add this ''' for comment but it still be the same output .My problem is for the urequest module because i don't know exactly how to write a'' post request '' using this module,this is the error i get:
'''
Traceback (most recent call last):
File "<stdin>", line 74, in <module>
File "<stdin>", line 50, in post_location
File "/flash/lib/urequests.py", line 115, in post
File "/flash/lib/urequests.py", line 53, in request
TypeError: function takes 2 positional arguments but 4 were given
''' -
The source quotation char is not the apostophe ' 0x27
It is the dead accent key ` 0x60 -
@oglucio can you show line 53 of your
/flash/lib/urequests.pyfile? I think to remember having seen somewhere that there's a change to make in a call somewhere for compatibility. Search fo urequests in the forum, you'll probably find a hint on that. -
@jcaron
#line53 and 54
ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
ai = ai[0] -
@jcaron all links that referred to urequest.py resolved on all the forum are no longer available.
-
@crumble i am using the qwerty [ita] i don't found it .Can you help me?
-
@oglucio said in http post requests:
@crumble i am using the qwerty [ita] i don't found it .Can you help me?
please use a civilised language like german or US english ;)
But even we can learn something. You have those strange french letters on your keyboard and therefore no special key to compose them. interesting. I have to pay more attention when I am in the alps.
you can switch to US layout and use the key left to the 1-key. Or use copy&paste.
But god news for you. Pycom updated the forum a few days ago. Now I see that we have a button for marking code. Use the </> button. And they gave us not only one ordinary button. No - we got two. So you can choose between the auto text ;)
-
@oglucio searched for "urequest arguments" and found this in 2 clicks:
https://forum.pycom.io/topic/3017/sending-sensor-data-to-server-using-lora/6
-
@jcaron still getting the same error
-
@oglucio it would be difficult to get the same error if you applied the fix given in that post.
Can you post the error and the corresponding line of your code?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login