Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    http post requests

    Scheduled Pinned Locked Moved Getting Started
    posturequestscodesample
    16 Posts 3 Posters 1.4k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      jcaron @oglucio
      last edited by jcaron

      @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.

      O 2 Replies Last reply Reply Quote 1
      • O Offline
        oglucio @jcaron
        last edited by

        '''
        #Library

        from network import WLAN
        from pytrack import Pytrack
        import urequests as requests
        from L76GNSS import L76GNSS
        import socket
        import json
        import time
        import pycom
        import machine

        py = 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())
        break

        Post

        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:
            pass
        

        lat = 53
        lng = -6

        main 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)
        

        '''

        1 Reply Last reply Reply Quote 0
        • O Offline
          oglucio @jcaron
          last edited by

          @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
          '''

          C J 2 Replies Last reply Reply Quote 0
          • C Offline
            crumble @oglucio
            last edited by

            The source quotation char is not the apostophe ' 0x27
            It is the dead accent key ` 0x60

            O 1 Reply Last reply Reply Quote 0
            • J Offline
              jcaron @oglucio
              last edited by

              @oglucio can you show line 53 of your /flash/lib/urequests.py file? 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.

              O 2 Replies Last reply Reply Quote 0
              • O Offline
                oglucio @jcaron
                last edited by

                @jcaron
                #line53 and 54
                ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
                ai = ai[0]

                1 Reply Last reply Reply Quote 0
                • O Offline
                  oglucio @jcaron
                  last edited by

                  @jcaron all links that referred to urequest.py resolved on all the forum are no longer available.

                  J 1 Reply Last reply Reply Quote 0
                  • O Offline
                    oglucio @crumble
                    last edited by

                    @crumble i am using the qwerty [ita] i don't found it .Can you help me?

                    C 1 Reply Last reply Reply Quote 0
                    • C Offline
                      crumble @oglucio
                      last edited by crumble

                      @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 ;)

                      1 Reply Last reply Reply Quote 1
                      • J Offline
                        jcaron @oglucio
                        last edited by

                        @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

                        O 1 Reply Last reply Reply Quote 0
                        • O Offline
                          oglucio @jcaron
                          last edited by

                          @jcaron still getting the same error

                          J 1 Reply Last reply Reply Quote 0
                          • J Offline
                            jcaron @oglucio
                            last edited by

                            @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?

                            1 Reply Last reply Reply Quote 0

                            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
                            • 1 / 1
                            • First post
                              Last post

                            Pycom on Twitter

                            Pycom