Just tried worldtimeapi.org and just get errors.
>>> %Run -c $EDITOR_CONTENT
MPY: soft reboot
Connected to Wi-Fi network.
('192.168.0.79', '255.255.255.0', '192.168.0.1', '194.168.4.100')
Traceback (most recent call last):
File "<stdin>", line 96, in <module>
File "requests/__init__.py", line 201, in get
File "requests/__init__.py", line 151, in request
ValueError: HTTP error: BadStatusLine:
[]
>>>
Here is the code:
import time
from presto import Presto
import network
import rp2
import requests
rp2.country("GB")
from secrets import WIFI_SSID, WIFI_PASSWORD
# Setup for the Presto display
presto = Presto(full_res=True)
display = presto.display
WIDTH, HEIGHT = display.get_bounds()
touch = presto.touch # Activate touch
# Create some colours
BLUE = display.create_pen(20,0,255)
WHITE = display.create_pen(255, 255, 255)
RED = display.create_pen(255,0,0)
ORANGE = display.create_pen(245, 165, 4)
GREEN = display.create_pen(0,255,0)
PINK = display.create_pen(250, 125, 180)
CYAN = display.create_pen(0,255,255)
MAGENTA = display.create_pen(255,0,255)
BLACK = display.create_pen(0, 0, 0)
YELLOW = display.create_pen(255, 255, 0)
def clean(): # Clear the screen to Black
display.set_pen(BLACK)
display.clear()
display.set_font("bitmap8") # Change the font
clean()
display.set_pen(RED)
display.text("World Time",40,200,460,8)
display.set_pen(BLUE)
display.text("http://worldtimeapi.org/api/timezone/Europe/London.txt",70,400,480,2)
display.text("Tony Goodhew, Leicester UK",120,450,480,2)
presto.update()
time.sleep(1)
clean()
display.set_pen(RED)
# Activate WiFi
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
max_wait = 30
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print("Waiting for Wi-Fi connection...")
display.set_pen(RED)
display.text("Waiting for Wi-Fi connection...",10,200,460,5)
presto.update()
time.sleep(1)
if wlan.status() != 3:
raise RuntimeError("Network connection failed")
else:
print("Connected to Wi-Fi network.")
print(wlan.ifconfig())
clean()
display.set_pen(GREEN)
display.text("Connected to WiFi",50,200,460,5)
display.set_pen(BLUE)
display.text(" Processing",70,260,460,5)
presto.update()
response = requests.get("http://worldtimeapi.org/api/timezone/Europe/London.txt")
print(response)
response.close()
What am I doing wrong?