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



  • 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



  • @seb Everything work fine, after sync again!

    Thank you very much



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


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

    thank you very much for your help!



  • @madeira199

    In the REPL console can you please run the following:

    import urequests as requests
    print(dir(requests))
    print(type(requests))
    


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



    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)
    

 

Pycom on Twitter