0

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"}

fileinput をクエリ文字列にフォーマットする方法がわかりません。書式設定は多少正しく見えますか? 区切り文字は、Python スクリプトに入るデータのスペースです。Raspberry Pi で Raspbian を使用しています。

4

1 に答える 1