|
Sorry the last http.request call had a typo. It is supposed to be:print(h.request{url="" href="http://192.168.0.197:49154/nasdevice.xml%5D" target="_blank">http://192.168.0.197:49154/nasdevice.xml]],sink=ltn12.sink.file(io.stdout),headers=hdrs})On Tue, Jul 15, 2014 at 2:01 PM, Milind Gupta <milind.gupta@gmail.com> wrote:
Hi,I have a NAS device Western Digital My Book live which is UPnP enabled. Its UPnP service description XML Is at an address like:When I try to get that file using the http module it gives me the error: invalid chunk size- The file can be viewed easily on the same computer using a web browser- The python url library is able to retrieve it as wellWhen I print what it received before that error message it is the 1st line of the XML file. The function generating the error is this in http.lua:socket.sourcet["http-chunked"] = function(sock, headers)return base.setmetatable({getfd = function() return sock:getfd() end,dirty = function() return sock:dirty() end}, {__call = function()-- get chunk size, skip extentionlocal line, err = sock:receive()if err then return nil, err endlocal size = base.tonumber(string.gsub(line, ";.*", ""), 16)if not size then return nil, "invalid chunk size" end-- was it the last chunk?if size > 0 then-- if not, get chunk and skip terminating CRLFlocal chunk, err, part = sock:receive(size)if chunk then sock:receive() endreturn chunk, errelse-- if it was, read trailers into headers tableheaders, err = receiveheaders(sock, headers)if not headers then return nil, err endendend})endIf I print line just before the tonumber conversion then the 1st line of the xml is printed out but from the code it seems it was expecting a chunk size number.For the same device I am able to retrieve another UPnP XML description file without any problem which resides on the address:This does not give the invalid chunk size error.
Both files are easily viewable from the web browser on the same computer.The command I use to retrieve the files are:h = require("socket.http")hdrs = {["USER-AGENT"]="uPNP/1.0",["CONTENT-TYPE"] = [[text/xml; charset="utf-8"]]}print(h.request{[[http://192.168.0.197:49154/nasdevice.xml]],sink=ltn12.sink.file(io.stdout),headers=hdrs})Is this server also not complying with the standard somehow? What would be the correct way to retrieve the xml file?Thanks,Milind