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

    How to make HTTPS requests

    Scheduled Pinned Locked Moved LoPy
    lopyhttpssslsockets
    7 Posts 3 Posters 3.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.
    • L Offline
      lebucur
      last edited by

      Hello, is there a way to make HTTPS requests?
      I have tried many different ways, but even wrapping a SSL socket generated errors. I am really confused right now.. I have LoPy with the latest firmware (1.6.13.b1).

      I 1 Reply Last reply Reply Quote 0
      • I Offline
        Innocenzo @lebucur
        last edited by

        @lebucur SSL should work if the WiPY (LoPy) is the client. The problem with ssl.wrap_socket() arises when the WiPy (LoPy) is the Server Side. Try also to use the urequests.py lib.

        1 Reply Last reply Reply Quote 1
        • D Offline
          danielm
          last edited by danielm

          I could do POST over HTTPS using urequests.py library, however it is unstable/unreliable:

          https://forum.pycom.io/topic/1061/https-post-using-urequests-py-and-guru-mediation-error/

          It works good enough for doing experiments but not for long-running applications.

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            lebucur @danielm
            last edited by

            Thanks,

            Will these be implemented officially in the near future? What alternatives do I have?
            I guess I could do well with TCP + separate encryption, right?

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

              I hope that the issue will be fixed soon, however it is fully in hands of Pycom team or maybe something will have to be fixed by Espressif in esp-idf.

              You could try to write your own library which will compile requests and parse responses, however if the issue is caused e.g. by ssl.wrap_socket() you will face similar behavior.

              1 Reply Last reply Reply Quote 0
              • L Offline
                lebucur
                last edited by

                I want to share with you the code that worked for me afterall:

                =========================================================================

                import socket, ssl

                server = ('192.168.0.105', 25566)

                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #def socket.IPPROTO_TCP
                sslsock = ssl.wrap_socket(sock)
                sslsock.connect(server)
                sslsock.send('GET /ping HTTP/1.0\r\n\r\n')
                print(sslsock.recv(200))
                sslsock.close() #automatically closes underlying socket

                ==============================================

                import urequests

                url = 'https://192.168.0.105:25566/ping'
                resp = urequests.request('GET', url)
                print(resp.content)

                ===============================================

                import urequests

                url = 'https://192.168.0.105:25566/register'
                headers = {'content-type': 'application/json'}
                data = {'email':'email@gmail.com', 'password':'password', 'fullName':'My Name'}

                resp = urequests.request('POST', url, json=data, headers=headers)
                print(resp.content)

                ======================================================================

                I still get OSERROR or EHOSTUNREACH from time to time, especially when I try to make these requests one after another. My guess is that there are some resources that are not freed when closing the socket.

                1 Reply Last reply Reply Quote 1
                • D Offline
                  danielm
                  last edited by

                  Does it work reliably if repeated for hundreds of requests? Properly raised exceptions are acceptable in my opinion.

                  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