Use "with" statement for opening the URL

This helps catch errors that may happen without making the door script
blow up.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Anna Schumaker 2015-04-07 14:30:19 -04:00
parent 4b8b596ae3
commit f86911a4d2
1 changed files with 4 additions and 4 deletions

View File

@ -80,10 +80,10 @@ from urllib import request
# Blocks for 5 seconds before resetting the door
def verify_key(key):
url = SERVER + ("/%s" % key)
if request.urlopen(url).read().decode() == "OK":
open_door()
time.sleep(5)
with request.urlopen(SERVER + ("/%s" % key)) as f:
if f.read().decode() == "OK":
open_door()
time.sleep(5)
close_door()