Skip to content

Commit 1b9a591

Browse files
committed
libs: Fix the exception caused by missing ssl module.
Signed-off-by: lbuque <[email protected]>
1 parent d4cb5c1 commit 1b9a591

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

m5stack/boards/manifest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
include("$(MPY_DIR)/extmod/asyncio")
1111
require("webrepl")
1212
require("upysh")
13+
require("ssl")
1314

1415
# freeze("$(MPY_DIR)/tools", ("upip.py", "upip_utarfile.py"))
1516
# freeze("$(MPY_DIR)/ports/esp8266/modules", "ntptime.py")

m5stack/libs/requests2/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import usocket
1+
import socket
22

33

44
class Response:
@@ -48,11 +48,11 @@ def request(
4848
chunked_data = data and getattr(data, "__next__", None) and not getattr(data, "__len__", None)
4949

5050
if auth is not None:
51-
import ubinascii
51+
import binascii
5252

5353
username, password = auth
5454
formated = b"{}:{}".format(username, password)
55-
formated = str(ubinascii.b2a_base64(formated)[:-1], "ascii")
55+
formated = str(binascii.b2a_base64(formated)[:-1], "ascii")
5656
headers["Authorization"] = "Basic {}".format(formated)
5757

5858
try:
@@ -63,7 +63,7 @@ def request(
6363
if proto == "http:":
6464
port = 80
6565
elif proto == "https:":
66-
import ussl
66+
import ssl
6767

6868
port = 443
6969
else:
@@ -73,14 +73,14 @@ def request(
7373
host, port = host.split(":", 1)
7474
port = int(port)
7575

76-
ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
76+
ai = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)
7777
ai = ai[0]
7878

7979
resp_d = None
8080
if parse_headers is not False:
8181
resp_d = {}
8282

83-
s = usocket.socket(ai[0], usocket.SOCK_STREAM, ai[2])
83+
s = socket.socket(ai[0], socket.SOCK_STREAM, ai[2])
8484

8585
if timeout is not None:
8686
# Note: settimeout is not supported on all platforms, will raise
@@ -90,7 +90,7 @@ def request(
9090
try:
9191
s.connect(ai[-1])
9292
if proto == "https:":
93-
s = ussl.wrap_socket(s, server_hostname=host)
93+
s = ssl.wrap_socket(s, server_hostname=host)
9494
s.write(b"%s /%s HTTP/1.0\r\n" % (method, path))
9595
if "Host" not in headers:
9696
s.write(b"Host: %s\r\n" % host)

m5stack/libs/umqtt/simple.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
import usocket as socket
6-
import ustruct as struct
7-
from ubinascii import hexlify
5+
import socket
6+
import struct
87

98

109
class MQTTException(Exception):
@@ -71,9 +70,9 @@ def connect(self, clean_session=True):
7170
addr = socket.getaddrinfo(self.server, self.port)[0][-1]
7271
self.sock.connect(addr)
7372
if self.ssl:
74-
import ussl
73+
import ssl
7574

76-
self.sock = ussl.wrap_socket(self.sock, **self.ssl_params)
75+
self.sock = ssl.wrap_socket(self.sock, **self.ssl_params)
7776
premsg = bytearray(b"\x10\0\0\0\0\0")
7877
msg = bytearray(b"\x04MQTT\x04\x02\0\0")
7978

@@ -100,7 +99,6 @@ def connect(self, clean_session=True):
10099

101100
self.sock.write(premsg, i + 2)
102101
self.sock.write(msg)
103-
# print(hex(len(msg)), hexlify(msg, ":"))
104102
self._send_str(self.client_id)
105103
if self.lw_topic:
106104
self._send_str(self.lw_topic)
@@ -140,7 +138,6 @@ def publish(self, topic, msg, retain=False, qos=0):
140138
sz >>= 7
141139
i += 1
142140
pkt[i] = sz
143-
# print(hex(len(pkt)), hexlify(pkt, ":"))
144141
self.sock.write(pkt, i + 1)
145142
self._send_str(topic)
146143
if qos > 0:
@@ -167,7 +164,6 @@ def subscribe(self, topic, qos=0):
167164
pkt = bytearray(b"\x82\0\0\0")
168165
self.pid += 1
169166
struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid)
170-
# print(hex(len(pkt)), hexlify(pkt, ":"))
171167
self.sock.write(pkt)
172168
self._send_str(topic)
173169
self.sock.write(qos.to_bytes(1, "little"))

0 commit comments

Comments
 (0)