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

    Not able to do GET using urequests library

    Scheduled Pinned Locked Moved Discussion
    http geturequests
    4 Posts 3 Posters 1.3k 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
      sprasad
      last edited by

      Hello,
      I'm trying to connect to the Internet and fetch a web page. To begin with, I was able to successfully connect to the hotspot on my mobile phone. Later, I'm trying to use urequests library ( https://github.com/micropython/micropython-lib/tree/master/urequests) to do a GET operation with a URL but failing. Here is my code

      nets = wlan.scan()
      for net in nets:
          if net.ssid == <MY SSID>:
              print('Network found!')
              wlan.connect(net.ssid, auth=(net.sec, 'MY PWD'), timeout=5000)
              while not wlan.isconnected():
                  machine.idle() # save power while waiting
              print('WLAN connection succeeded!') #This is displayed
              
              url = "http://en.wikipedia.org/wiki/Monty_Python"
              r = requests.get(url) 
              #Error - TypeError: function takes 2 positional arguments but 
              #four were given
              print(r)
              print(r.content)
              r.close()
              break
      

      Even though I'm passing only one argument i.e., URL, how am I getting the above mentioned error? Am I missing something here?
      Also, if there is a tried and tested library that works well for HTTP GET and POST operation with GPy, please suggest the same so that I can try that out.

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino @sprasad
        last edited by

        @sprasad
        Please change line 53 in urquests.py to be just

        ai = usocket.getaddrinfo(host, port)

        S 1 Reply Last reply Reply Quote 2
        • S Offline
          sprasad @jmarcelino
          last edited by

          @jmarcelino That worked! Thank you..

          1 Reply Last reply Reply Quote 1
          • L Offline
            lilou
            last edited by

            Hi, could you please tell me where can I find the urequests.py

            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