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

    urequests with ussl causes an OSError

    Scheduled Pinned Locked Moved MicroPython
    urequestsoserrorpost
    6 Posts 3 Posters 2.3k Views 4 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.
    • A Offline
      ahmedkalnaggar
      last edited by

      On my WiPy 2.0 Board, When trying to get or post (to https links) every n amount of seconds using the urequests library it works fine and make around 10-15 successful requests then suddenly it raises an OSError -1 . And The Error points me to line 56 in the urequests source code which is:
      s = ussl.wrap_socket(s, server_hostname=host)
      Normally I would catch any exception that occurs and try to POST it again or POST another packet.
      However, if an OSError occurs all the next Requests fails too which forces me to reset the board.

      1 Reply Last reply Reply Quote 1
      • D Offline
        Devang Sharma
        last edited by

        Hello @ahmedkalnaggar,

        I've been facing a similar issue with my LoPy. I've also asked in a thread.
        https://forum.pycom.io/topic/2164/lopy-http-post-request-oserror
        Have you solved the issue?

        1 Reply Last reply Reply Quote 0
        • A Offline
          ahmedkalnaggar
          last edited by

          @devang-sharma yes, by using gc.collect() after each request.

          D 1 Reply Last reply Reply Quote 0
          • D Offline
            Devang Sharma @ahmedkalnaggar
            last edited by

            @ahmedkalnaggar Didn't work on my LoPy. Still getting the same error!

            1 Reply Last reply Reply Quote 0
            • T Offline
              this.wiederkehr
              last edited by

              @devang-sharma said in urequests with ussl causes an OSError:

              @ahmedkalnaggar Didn't work on my LoPy. Still getting the same error!

              I might be going to face similar problems as I intend to use urequests lib to (up to now I did not come accross that problem). Therefore I am interested in the solution too.

              Are you guys aware that you have to manually close the socket after each request?

              See the last line of the example:
              https://github.com/micropython/micropython-lib/blob/master/urequests/example_xively.py

              try:
                  import urequests as requests
              except ImportError:
                  import requests
              
              r = requests.get("http://api.xively.com/")
              print(r)
              print(r.content)
              print(r.text)
              print(r.content)
              print(r.json())
              
              # It's mandatory to close response objects as soon as you finished
              # working with them. On MicroPython platforms without full-fledged
              # OS, not doing so may lead to resource leaks and malfunction.
              r.close()
              
              
              D 1 Reply Last reply Reply Quote 2
              • D Offline
                Devang Sharma @this.wiederkehr
                last edited by

                @this-wiederkehr You've got the point. I've tried this and finally, it works without any error. Thanks a lot.

                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