WiPy HTTPS call
-
I'm trying to do an HTTPS call, using WiPy, but getting an OSError: -32512 when calling ssl.wrap_socket(s).
Here's my code
s = _socket.socket() ai = _socket.getaddrinfo("google.com", 443) print("Address infos:", ai) addr = ai[0][-1] print("Connect address:", addr) s.connect(addr) s = ssl.wrap_socket(s) print(s) s.write(b"GET / HTTP/1.0\r\n\r\n") print(s.read(4096)) s.close()
Do you have any idea, what I'm doing wrong?
-
I have the same problem: https://forum.pycom.io/topic/1056/ssl-socket-communication-between-wipy-2-0
But if I try to connect with the wipy to a secure Server with ssl
#client side import usocket as socket import ssl from network import WLAN import machine wlan = WLAN(mode=WLAN.STA) wlan.connect('TP-LINK_2.4GHz_E113DF', auth=(WLAN.WPA2,"***********")) while not wlan.isconnected(): machine.idle() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) # Require a certificate from the server. We used a self-signed certificate # so here ca_certs must be the server certificate itself. ssl_sock = ssl.wrap_socket(s,cert_reqs=ssl.CERT_REQUIRED,ca_certs='cert.pem') ssl_sock.connect(('192.168.1.125', 10023)) ssl_sock.write(b"boo!") data = ssl_sock.read() print(data) ssl_sock.close()
It works without problems. Try to use:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
instead of
s = socket.socket()
But if I try to set a WiPy as a Server, I receive a Guru Meditation Error. More datails are in the topic linked early.
-
I am having similar experience with Guru meditation errors when doing HTTPS requests: https://forum.pycom.io/topic/1061/https-post-using-urequests-py-and-guru-mediation-error
Daniel promised to find a solution for this issue.
-
@bucknall Hi.
Hi, I've tried your example, but I still have a "Guru meditation error".
It seems to be from the use of the ssl library: I tried to connect to google without ssl and I did not have any problems.
The error appeared when I tried to connect via ssl, as in your example.
I attach the sources and the results of the two versions.Connect to google without ssl, port 80
---------------------[start src]
import network
import machine
import time
import socket
import sslWifiNetworkName = "here wifi ssid"
WifiPassword = "here wifi password"
wlan = network.WLAN(mode=network.WLAN.STA)
wlan.connect(WifiNetworkName, auth=(network.WLAN.WPA2, WifiPassword), timeout=5000)
while not wlan.isconnected():
machine.idle()
print("Connected to Wifi\n")
print(wlan.ifconfig())
s = socket.socket()
ai = socket.getaddrinfo("google.com", 80)
addr = ai[0][-1]
s.connect(addr)
s.write(b"GET / HTTP/1.0\r\n\r\n")
print("----------------[start]")
print(s.read(4096))
print("----------------[end]")
s.close()
---------------------[end src]Results:
import thttpok.py
I (22198) wifi: Init ampdu: 0
I (22198) wifi: mode : sta (24:0a:c4:00:d6:94)
I (22199) wifi: sleep disable
I (23079) wifi: n:6 0, o:6 0, ap:255 255, sta:6 0, prof:6
I (24068) wifi: state: init -> auth (b0)
I (24070) wifi: state: auth -> assoc (0)
I (24073) wifi: state: assoc -> run (10)
I (24088) wifi: connected with Vodafone-33852835, channel 6
Connected to Wifi('192.168.1.5', '255.255.255.0', '192.168.1.1', '192.168.1.1')
----------------[start]
b'HTTP/1.0 302 Found\r\nCache-Control: private\r\nContent-Type: text/html; charset=UTF-8\r\nReferrer-Policy: no-referrer\r\nLocation: http://www.google.it/?gfe_rd=cr&ei=2RkCWeKtBOTBXrS3t4gD\r\nContent-Length: 256\r\nDate: Thu, 27 Apr 2017 16:18:33 GMT\r\n\r\n<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">\n<TITLE>302 Moved</TITLE></HEAD><BODY>\n<H1>302 Moved</H1>\nThe document has moved\n<A HREF="http://www.google.it/?gfe_rd=cr&ei=2RkCWeKtBOTBXrS3t4gD">here</A>.\r\n</BODY></HTML>\r\n'
----------------[end]This is another version of the same software, using the ssl connection, like in your example, I have “Guru Meditation Error: Core 0 panic'ed (abort)”:
Connect to google with ssl, port 443
---------------------[start src]
import network
import machine
import time
import socket
import sslWifiNetworkName = "here wifi ssid"
WifiPassword = "here wifi password"
wlan = network.WLAN(mode=network.WLAN.STA)
wlan.connect(WifiNetworkName, auth=(network.WLAN.WPA2, WifiPassword), timeout=5000)
while not wlan.isconnected():
machine.idle()
print("Connected to Wifi\n")
print(wlan.ifconfig())
s = socket.socket()
ai = socket.getaddrinfo("google.com", 443)
addr = ai[0][-1]
ss = ssl.wrap_socket(s)
ss.connect(addr)
ss.write(b"GET / HTTP/1.0\r\n\r\n")
print("----------------[start]")
print(ss.read(4096))
print("----------------[end]")
ss.close()
---------------------[end src]Results:
import thttps2.py
I (34325) wifi: Init ampdu: 0
I (34325) wifi: mode : sta (24:0a:c4:00:d6:94)
I (34326) wifi: sleep disable
I (34455) wifi: n:1 0, o:6 0, ap:255 255, sta:1 0, prof:6
I (35443) wifi: state: init -> auth (b0)
I (35446) wifi: state: auth -> assoc (0)
I (35449) wifi: state: assoc -> run (10)
I (35464) wifi: connected with Vodafone-33852835, channel 1
Connected to Wifi('192.168.1.5', '255.255.255.0', '192.168.1.1', '192.168.1.1')
I (45450) wifi: pm start, type:0abort() was called at PC 0x4014c133
Guru Meditation Error: Core 0 panic'ed (abort)Backtrace: 0x40085692:0x3ffc4f60 0x40086470:0x3ffc4f80 0x4015023c:0x3ffc4fb0 0x4015057f:0x3ffc4fe0 0x40150706:0x3ffc5060 0x4014bba2:0x3ffc5080
……..
/////wAAAAAAAAAAAAAAAFwz+z8AAAAAAQAAAAAAAAAAAAAAQDj7PwAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAPYMCICAPP4/+Dn8PyxK+z8AAAAAAAAAAEw4+z8AAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
================= CORE DUMP END =================
Rebooting...
ets Jun 8 2016 00:22:57rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:QIO, clock div:2
load:0x3fff9010,len:8
load:0x3fff9018,len:248
load:0x40078000,len:4056
load:0x4009fc00,len:920
entry 0x4009fde4
I (1548) wifi: wifi firmware version: 90b1b8b
I (1549) wifi: config NVS flash: disabled
I (1549) wifi: config nano formating: disabled
I (1564) wifi: Init dynamic tx buffer num: 32
I (1565) wifi: wifi driver task: 3ffd63f4, prio:23, stack:3584
I (1565) wifi: Init static rx buffer num: 10
I (1567) wifi: Init dynamic rx buffer num: 0
I (1571) wifi: Init rx ampdu len mblock:7
I (1575) wifi: Init lldesc rx ampdu entry mblock:4
I (1579) wifi: wifi power manager task: 0x3ffdb7b0 prio: 21 stack: 2560
I (1586) wifi: sleep disable
I (2575) wifi: wifi timer task: 3ffdc844, prio:22, stack:3584
I (2591) wifi: Init ampdu: 0
I (2591) wifi: mode : softAP (24:0a:c4:00:d6:95)
MicroPython v1.8.6-593-g8e4ed0fa on 2017-04-12; LoPy with ESP32
Type "help()" for more information.
-
Hi @bucknall
This code works for me in general. But doing further investigation, I found out, that I still get the error while running the code within a call back for the Blutooth write event:
char1_cb = chr1.callback(trigger=Bluetooth.CHAR_WRITE_EVENT, handler=char1_cb)
-
Hi @Tineler,
I've just been testing your code - I'm not sure what's throwing the error exactly but I believe that it's coming from trying to wrap an existed and connected socket with ssl. I think this behaviour is unexpected, so I'll report it internally.
I re-wrote your example but wrapped the socket with ssl before connecting them and it seemed to work without issue. Maybe try to use the example below:
import socket import ssl s = socket.socket() ai = socket.getaddrinfo("google.com", 443) addr = ai[0][-1] ss = ssl.wrap_socket(s) ss.connect(addr) ss.write(b"GET / HTTP/1.0\r\n\r\n") print(ss.read(4096)) ss.close()
Let me know if that works for you!
-
I also get the error message when trying code from Pycom documentation.