Jan-20-2020, 06:22 PM
Hey guys,
I have been doing the 'Where is the Space Station?' project on the wonderful Raspberry Pi website and have encountered a problem. When I run the full code on Trinket online editor (as it says to) this error keeps popping up: 'KeyError: response on line 57 in main.py'. I have done some research on what a KeyError is but can't figure out the error. This is the link to the site: 'https://projects.raspberrypi.org/en/projects/where-is-the-space-station/' (leave out the apostrophes).
Here is my code:
Birdwatcher.
I have been doing the 'Where is the Space Station?' project on the wonderful Raspberry Pi website and have encountered a problem. When I run the full code on Trinket online editor (as it says to) this error keeps popping up: 'KeyError: response on line 57 in main.py'. I have done some research on what a KeyError is but can't figure out the error. This is the link to the site: 'https://projects.raspberrypi.org/en/projects/where-is-the-space-station/' (leave out the apostrophes).
Here is my code:
import json
import turtle
import time
import urllib.request
url = 'http://api.open-notify.org/astros.json'
response = urllib.request.urlopen(url)
result = json.loads(response.read())
print('People in space: ', result['number'])
people = result['people']
for p in people:
print(p['name'], 'in the', p['craft'])
url = 'http://api.open-notify.org/iss-now.json'
response = urllib.request.urlopen(url)
result = json.loads(response.read())
screen = turtle.Screen()
screen.setup(720, 360)
screen.setworldcoordinates(-180, -90, 180, 90)
screen.bgpic('map.gif')
location = result['iss_position']
lon = float(location['latitude'])
lat = float(location['latitude'])
print('Latitude: ', lat)
print('Longitude: ', lon)
screen.register_shape('iss.gif')
iss = turtle.Turtle()
iss.shape('iss.gif')
iss.setheading(90)
iss.penup()
iss.goto(lon, lat)
lat = 52.183
lon = 0.216712239
location = turtle.Turtle()
location.penup()
location.color('yellow')
location.goto(lon,lat)
location.dot(5)
location.hideturtle()
url = 'http://api.open-notify.org/iss-pass.json'
url = url + '?lat=' + str(lat) + '?lon' + str(lon)
response = urllib.request.urlopen(url)
result = json.loads(response.read())
over = result['response'][1]['risetime']
style = ('Mono', 6, 'bold')
location.write(time.ctime(over), font=style)
print(over)Thanks, Birdwatcher.
