我有一个接受 bash 命令“ibeacon_scan”输出的 python 脚本。运行脚本时出现此错误。
Traceback (most recent call last):
file "./stdin.py", line 12, in <module>
conn.request("POST", "post.php", params, headers)
NameError: name 'params is not defined
这是python的代码
#!/usr/bin/python
import fileinput
import httplib
import urllib
for line in fileinput.input():
parmas = urllib.urlencode({"UUID": {"Major":{"Minor":"RSSI"}}})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = httplib.HTTPConnection("67.205.14.22")
conn.request("POST", "post.php", params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
print data
conn.close()
“ibeacon_san”命令的输出是:
ibeacon scan...
3F234454-CFD-4A0FF-ADF2-F4911BA9FFA6 1 4 -71 -69
3F234454-CFD-4A0FF-ADF2-F4911BA9FFA6 6 2 -71 -63
3F234454-CFD-4A0FF-ADF2-F4911BA9FFA6 1 4 -71 -69
3F234454-CFD-4A0FF-ADF2-F4911BA9FFA6 5 7 -71 -64
我的问题是,如何更改我的脚本发送查询字符串,例如:
http://67.205.14.22/post.php/ProcessRawData?data={"UUID":"3F234454-CFD-4A0FF-ADF2-F4911BA9FFA6","timestamp":"2010-04-12 10:54:24","Major": "1","Minor": "4","RSSI":"-69"}
我不知道如何将文件输入格式化为查询字符串。我的格式看起来有些正确吗?分隔符是进入 python 脚本的数据的空间。我在树莓派上使用 Raspbian。