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

    import urequest

    Scheduled Pinned Locked Moved WiPy 2&3
    3 Posts 3 Posters 184 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.
    • S Offline
      serenabilly
      last edited by

      Hi all, i'm new and beginner but i've some experiance with raspberry,esp 8266,Tasmota,php,python,html.
      I bought recently a wipy 3,0 + pycom makr board. Pymakr software don't working on Win 10 then i use ATOM with pymakr package.
      My first trouble is the import of urequest module and http module.

      import urequests
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      ImportError: no module named 'urequests'

      I've last firmware installed but seem this module don't exist for my board. Why? Realy?

      And the second problem on this code :

      import machine,usocket
      from network import WLAN
      wlan = WLAN(mode=WLAN.STA)
      nets = wlan.scan()
      for net in nets:
      if net.ssid == 'CAMERE':
      print('Network found!')
      wlan.connect(net.ssid, auth=(net.sec, 'karate75'), timeout=5000)
      while not wlan.isconnected():
      machine.idle() # save power while waiting
      print('WLAN connection succeeded!')
      break

      s = usocket.socket()
      s.connect(usocket.getaddrinfo('www.micropython.org', 80)[0][-1])

      Response:

      Network found!
      WLAN connection succeeded!
      Traceback (most recent call last):
      File "<stdin>", line 15, in <module>
      OSError: Network card not available

      Pycom MicroPython 1.20.2.rc6 [v1.11-01f49f7] on 2020-02-28; WiPy with ESP32
      Pybytes Version: 1.3.1
      Type "help()" for more information.

      Network card not available ???????????????????????????????????????????? Why? :(

      I'm stuck here. I neet to do https request to my apache server mounted on raspberry.
      I find a lot of examples on the net it use urequest with micropython but on my wipy board i can't import it!

      Please tell me why!
      I thanks all.

      1 Reply Last reply Reply Quote 0
      • D Offline
        dgerman
        last edited by

        Although I don't have an answer as to why system reports: "Network card not available"
        I have a concern about what seems to be common practice relating to waiting for an attach or connect to any network device.
        We should avoid using the statement

        while not wlan.isconnected():
        

        especially with the timeout option on the connect call.
        This will cause the system to hang if attach or connect can not be completed until manually reset or WatchDogTImer expiration.
        A better approach is to use a limiting loop for example:

        for ca in range (1,5):                  #  Experienced 3 once
            pycom.rgbled(0x504040)  #   bright pink means connecting to network
            if lte.isconnected() == True:
                break
            pycom.rgbled(0x000000)  #   dark
            time.sleep(.1)
            if ca == 5:
                   machine.deepsleep(5) # cause a soft reset, retaining TimeOfDayclock, in 5 ms
             
        

        Of course the range and the timing of the sleep should be tuned based on experience.
        Blinking the LED is up to you and only worth anything if the system is somewhere that you can see it.

        1 Reply Last reply Reply Quote 0
        • X Offline
          xmario
          last edited by

          I had the same problem, and it was because the "urequest" module is not inside the LoPy, you've to upload it yourself with your project.

          https://github.com/micropython/micropython-lib/blob/master/urequests/urequests.py

          Here you can find an "official" one to use!

          1 Reply Last reply Reply Quote 1

          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