-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverrequest.py
More file actions
31 lines (30 loc) · 840 Bytes
/
serverrequest.py
File metadata and controls
31 lines (30 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import urllib2, time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
if(not GPIO.input(17)):
print("Loading")
time.sleep(0.5)
req = urllib2.Request('http://www.google.com')
try:
resp = urllib2.urlopen(req)
except urllib2.HTTPError as e:
if e.code == 404:
print "abc"
# do something...
else:
# ...
print "def"
except urllib2.URLError as e:
# Not an HTTP-specific error (e.g. connection refused)
# ...
print "ofb"
else:
# 200
body = resp.read()
print body
else:
time.sleep(0.5)
print "Button not Pressed"