我使用sudo apt-get install python-pycurl安装了pycurl但是当我运行代码时它只显示:
Traceback (most recent call last): File "/home/pi/desktop/doorsensor.py", line 1, in <module> import pycurl, json importError: No module named pycurl
有人可以帮忙吗?
这是我的代码
import pycurl, json
from StringIO import StringIO
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
appID = "56cbc8e95659e3f40dc56c64"
appSecret = "a8c3c0302545ad64f71f7aa5f10e52ef"
pushEvent = "DoorAlert"
pushMessage = "Door Opened!"
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https:api.instapush.im/v1/post')
c.seopt(c.HTTPHEADER, ['x-instapush-appid: ' + appID,
'x-instapush-appsecret: ' + appSecret,
'Content-Type: application/json'])
json_fields = {}
json_fields['event']=pushEvent
json_fields['trackers'] = {}
json_fields['trackers']['message']=pushMessage
postfields = json.dumps(json_fields)
c.setopt(c.POSTFIELDS, postfields)
c.setopt(c.WRITEFUNCTION, buffer.write)
c.setopt(c.VERBOSE, True)
while True:
GPIO.wait_for_edge(23, GPIO.RISING)
print("Door Opened!\n")
c.perform()
body= buffer.getvalue()
print(body)
buffer.turncate(0)
buffer.seek(0)
GPIO.wait_for_edge(23, GPIO.FALLING)
print("Door Closed!\n")
c.close()
GPIO.cleanup()
好的,所以我在其中运行了Python v2.7。它的工作原理。 但现在我得到了
traceback (most recent call last):
File "/home/pi/Desktop/doorSensor.py", line 5, in <module>
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
RuntimeError: No access to /dev/mem. Try running as root!