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

    Gpy + Pysense - urequests AttributeError: 'module' object has no attribute 'get'

    Scheduled Pinned Locked Moved GPy
    gpypsensehttp geturequestsurequest.py
    7 Posts 2 Posters 2.0k Views 2 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.
    • M Offline
      madeira199
      last edited by seb

      Hi

      I am trying to make an HTTP get request for testing but have getting this message:
      urequests.py library downloaded from https://github.com/micropython/micropython-lib/tree/master/urequests

      Please give me some help, i am started with Pycom...

      Network found!
      WLAN connection succeeded!

      RTC Set from NTP to UTC: (2018, 2, 28, 14, 23, 38, 97276, None)
      Traceback (most recent call last):
      File "main.py", line 11, in <module>
      AttributeError: 'module' object has no attribute 'get'
      MicroPython v1.8.6-849-055728a on 2018-02-13; GPy with ESP32
      Type "help()" for more information.

       # boot.py
      import machine
      from network import WLAN
      
      wlan = WLAN(mode=WLAN.STA)
      
      nets = wlan.scan()
      for net in nets:
          if net.ssid == 'REMOVED':
              print('Network found!')
              wlan.connect(net.ssid, auth=(net.sec, 'REMOVED.'), timeout=5000)
              while not wlan.isconnected():
                  machine.idle() # save power while waiting
              print('WLAN connection succeeded!')
      
      # main.py
      
      import urequests as requests
      import utime
      from machine import RTC
      
      rtc = machine.RTC()
      rtc.ntp_sync("pool.ntp.org")
      utime.sleep_ms(750)
      print('\nRTC Set from NTP to UTC:', rtc.now())
      
      r = requests.get('http://api.xively.com/')
      print(r)
      print(r.content)
      print(r.text)
      print(r.content)
      print(r.json())
      
      r.close()
      

      0_1519827866858_17635791-c77c-49ba-8a92-832e33d3f5b1-image.png

      0_1519827882838_e676a105-68d9-4b54-8e05-6c1d5338e9a3-image.png

      0_1519827897700_c4daf312-3d17-4c38-baaa-b1a8452791e5-image.png

      1 Reply Last reply Reply Quote 0
      • sebS Offline
        seb
        last edited by

        1. Are you on the latest firmware?
        2. Are you sure you have correctly downloaded the urequest.py file from the link you provided? When I attempted to run this code I could not replicate your error. I did however have to patch line 53 to be:
            ai = usocket.getaddrinfo(host, port)
        
        M 1 Reply Last reply Reply Quote 0
        • M Offline
          madeira199 @seb
          last edited by

          @seb Yes i have the latest firmware, updated yesterday, Gpy, and Pysense

          i have patch line 53, and the problem remains
          0_1519831633134_c10561ad-977e-4c36-8789-1633ad38062b-image.png

          sebS 1 Reply Last reply Reply Quote 0
          • sebS Offline
            seb @madeira199
            last edited by

            @madeira199

            In the REPL console can you please run the following:

            import urequests as requests
            print(dir(requests))
            print(type(requests))
            
            M 1 Reply Last reply Reply Quote 0
            • M Offline
              madeira199 @seb
              last edited by

              @seb 0_1519832656878_ddfd0422-4584-428d-8911-8fa806db1689-image.png

              thank you very much for your help!

              sebS 1 Reply Last reply Reply Quote 0
              • sebS Offline
                seb @madeira199
                last edited by

                @madeira199

                Ah there seems to have been an issue syncing the library because the output should be:

                >>> import urequests as requests
                >>> print(dir(requests))
                ['put', 'post', 'usocket', 'patch', 'request', '__file__', '__name__', 'delete', 'head', 'Response', 'get']
                >>> print(type(requests))
                <class 'module'>
                

                Can you please run the following to clear your device and sync again:

                import os
                os.mkfs('/flash')
                
                M 1 Reply Last reply Reply Quote 0
                • M Offline
                  madeira199 @seb
                  last edited by

                  @seb Everything work fine, after sync again!

                  Thank you very much

                  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