大家好我试图通过php.wsdl网络服务发送我的温度和湿度传感器, 我需要将数据解析到webservice,以便我可以从webservice将其插入到mysql数据库中。
我遇到了一些问题,请指教
这是我的剧本:
#!/usr/bin/python
import time
from suds.client import Client
url = "http://172.20.xxx.xx``/SCS/WebService/webS.php?wsdl"
client = Client(url)
while(True):
# Run the DHT program to get the humidity and temperature readings!
output = subprocess.check_output(["./Adafruit_DHT", "2302", "4"]);
print output
matches = re.search("Temp =\s+([0-9.]+)", output)
if (not matches):
time.sleep(3)
continue
temp = float(matches.group(1))
# search for humidity printout
matches = re.search("Hum =\s+([0-9.]+)", output)
if (not matches):
time.sleep(3)
continue
humidity = float(matches.group(1))
print "Temperature: %.1f C" % temp
print "Humidity: %.1f %%" % humidity
# Append the data , including a timestamp
try:
values = [datetime.datetime.now(), temp, humidity]
except:
print "Unable to append data. Check your connection?"
sys.exit()
这是遇到的错误
追踪(最近一次呼叫最后一次):
File "./websvc.py", line 13, in <module>
output = subprocess.check_output(["./Adafruit_DHT", "2302", "4"]);
NameError: name 'subprocess' is not defined
我正在尝试使用此站点的教程/脚本中的python suds。请指教。 http://bradsrpi.blogspot.sg/2013/03/raspberry-pi-soap-web-service-client.html
答案 0 :(得分:0)
@ user1449266是对的。
你需要把
import subprocess
在文件的开头:
#...
import time
import subprocess
from suds.client import Client
#...
然后子进程模块在名称subprocess下已知,并且在写入subprocess.check_output
时,会找到子进程的属性check_output
。