How to make HTTPS requests

  • 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).

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

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


    import socket, ssl

    server = ('', 25566)

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


    import urequests

    url = ''
    resp = urequests.request('GET', url)


    import urequests

    url = ''
    headers = {'content-type': 'application/json'}
    data = {'email':'', 'password':'password', 'fullName':'My Name'}

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


    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.

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

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

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

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

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

Pycom on Twitter

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.