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:
parent
4b8b596ae3
commit
f86911a4d2
4
doors.py
4
doors.py
|
@ -80,8 +80,8 @@ 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":
|
||||
with request.urlopen(SERVER + ("/%s" % key)) as f:
|
||||
if f.read().decode() == "OK":
|
||||
open_door()
|
||||
time.sleep(5)
|
||||
close_door()
|
||||
|
|
Loading…
Reference in New Issue