waffle icon indicating copy to clipboard operation
waffle copied to clipboard

request.lua:67: attempt to index local 'ctype'

Open christopher5106 opened this issue 9 years ago • 2 comments

I got this kind of error during a POST

Request from POST/api/v1/
/root/torch/install/bin/luajit: /root/torch/install/share/lua/5.1/waffle/request.lua:67: attempt to index local 'ctype' (a nil value) stack traceback: /root/torch/install/share/lua/5.1/waffle/request.lua:67: in function '_getform' /root/torch/install/share/lua/5.1/waffle/request.lua:140: in function 'Request' /root/torch/install/share/lua/5.1/waffle/app.lua:93: in function 'handler' /root/torch/install/share/lua/5.1/async/http.lua:161: in function </root/torch/install/share/lua/5.1/async/http.lua:110> [C]: in function 'execute' /root/torch/install/share/lua/5.1/async/http.lua:224: in function 'cb' /root/torch/install/share/lua/5.1/async/handle.lua:33: in function </root/torch/install/share/lua/5.1/async/handle.lua:32> [C]: in function 'run' /root/torch/install/share/lua/5.1/async/init.lua:35: in function 'go' /root/torch/install/share/lua/5.1/waffle/app.lua:143: in function 'listen' api/init.lua:88: in main chunk [C]: in function 'dofile' /root/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk [C]: at 0x00406670

Thanks a lot for your help

christopher5106 avatar Sep 04 '16 11:09 christopher5106

The errors comes with Python post :

r = requests.post(url, data=param, files={'file': open(img_path, 'rb')})

It works with cURL:

curl URL -F "file=@test/test_imgs/sushi.jpg" -F "model=default"

christopher5106 avatar Sep 04 '16 11:09 christopher5106

I verified. Indeed, with python-requests, there is no content-type header. Cf http://docs.python-requests.org/en/master/user/quickstart/, section Post a multipart-encoded file. To have the content type, it is optional with the following syntax :

url = 'http://httpbin.org/post' files = {'file': ('report.xls', open('report.xls', 'rb'), 'application/vnd.ms-excel', {'Expires': '0'})} r = requests.post(url, files=files)

So it might be good to have the server work without content type header.

christopher5106 avatar Sep 04 '16 20:09 christopher5106