We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a5d2af7 commit a5d07c3Copy full SHA for a5d07c3
1 file changed
examples/network/http_client.py
@@ -1,21 +1,23 @@
1
try:
2
- import usocket as _socket
+ import usocket as socket
3
except:
4
- import _socket
+ import socket
5
6
7
-s = _socket.socket()
+s = socket.socket()
8
9
-ai = _socket.getaddrinfo("google.com", 80)
+ai = socket.getaddrinfo("google.com", 80)
10
print("Address infos:", ai)
11
addr = ai[0][4]
12
13
print("Connect address:", addr)
14
s.connect(addr)
15
16
if 0:
17
- # MicroPython rawsocket module supports file interface directly
18
- s.write("GET / HTTP/1.0\n\n")
+ # MicroPython socket objects support stream (aka file) interface
+ # directly, but the line below is needed for CPython.
19
+ s = s.makefile("rwb", 0)
20
+ s.write(b"GET / HTTP/1.0\n\n")
21
print(s.readall())
22
else:
23
s.send(b"GET / HTTP/1.0\n\n")
0 commit comments