docs/esp8266/tutorial: Make http_get sample function self contained.

This commit is contained in:
Thiago Paes 2018-11-01 21:47:43 -03:00 committed by Damien George
parent d1ed73ca8f
commit 5463ab6df6

View File

@ -61,6 +61,7 @@ of the request you need to specify the page to retrieve.
Let's define a function that can download and print a URL::
def http_get(url):
import socket
_, _, host, path = url.split('/', 3)
addr = socket.getaddrinfo(host, 80)[0][-1]
s = socket.socket()
@ -74,8 +75,7 @@ Let's define a function that can download and print a URL::
break
s.close()
Make sure that you import the socket module before running this function. Then
you can try::
Then you can try::
>>> http_get('http://micropython.org/ks/test.html')