Python 使用Lua执行httppost
我已经编写了一个Python脚本,它将数据发布到ApacheWebServer,数据很好地到达了$\u POST和$\u文件中。现在我想在Lua中实现同样的东西,但我还不能让它运行 我的Python代码如下所示:Python 使用Lua执行httppost,python,http,post,lua,http-headers,Python,Http,Post,Lua,Http Headers,我已经编写了一个Python脚本,它将数据发布到ApacheWebServer,数据很好地到达了$\u POST和$\u文件中。现在我想在Lua中实现同样的东西,但我还不能让它运行 我的Python代码如下所示: try: wakeup() socket.setdefaulttimeout(TIMEOUT) opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHan
try:
wakeup()
socket.setdefaulttimeout(TIMEOUT)
opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
host = HOST
func = "post_img"
url = "http://{0}{1}?f={2}&nodemac={3}&time={4}".format(host, URI, func, nodemac, timestamp)
if os.path.isfile(filename):
data = {"data":open(filename,"rb")}
print "POST time "+str(time.time())
response = opener.open(url, data, timeout=TIMEOUT)
retval = response.read()
if "SUCCESS" in retval:
return 0
else:
print "RETVAL: "+retval
return 99
except Exception as e:
print "EXCEPTION time "+str(time.time())+" - "+str(e)
return 99
到目前为止,我提出的Lua代码:
#! /usr/bin/lua
http = require("socket.http")
ltn12 = require("ltn12")
http.request{
url = "localhost/test.php?test=SEMIOS",
method = "POST",
headers = {
["Content-Type"] = "multipart/form-data; boundary=127.0.1.1.1000.17560.1375897994.242.1",
["Content-Length"] = 7333
},
source = ltn12.source.file(io.open("test.gif")),
sink = ltn12.sink.table(response_body)
}
print(response_body[1]) --response to request
但这段代码在执行时一直让我觉得:
$ ./post.lua
/usr/bin/lua: ./post.lua:17: attempt to index global 'response_body' (a nil value)
stack traceback:
./post.lua:17: in main chunk
[C]: ?
reg@DesktopOffice:~$
有几个使用Lua:and发送POST数据的示例。直接处理文件,这与您使用的非常接近
您对这个问题的描述与实际情况不符。我很困惑,您是想编写一个与Python脚本相同的客户端Lua脚本,还是想编写一个服务器端Lua脚本来处理Python脚本发送的数据?@Paul,我需要编写一个与Python脚本相同的Lua脚本,对