clementfarabet / async

An async framework for Lua/Torch.
116 stars 35 forks source link

Not working with python requests library #21

Closed subu-cliqz closed 9 years ago

subu-cliqz commented 9 years ago

The example json server code does not seem to be working with the python requests library as a client, fails with a "Bad json request" error.

SERVER IN LUA:

local async = require 'async'
require 'nn'

async.json.listen({host='0.0.0.0', port=8082}, function(req,res)
   print('request:',req)
   res({
      msg = 'my answer:',
      attached = 'pretty pretty pretty goooood.'
   })

   collectgarbage()
   print(collectgarbage("count") * 1024)
end)

async.go()

CLIENT IN PYTHON:

import requests
import json
payload = {'msg':'Hey', 'attached':'How are you'}
requests.get('xx.xx.xx.xx:8082', json.dumps(payload))
offbit commented 8 years ago

@subu-cliqz I had the same problem. Any hints ?

subu-cliqz commented 8 years ago

@efva I dont exactly remember now, but I think I fixed it by compacting my json before sending it. Something along the lines of separators=(',',':') in json.dumps()

offbit commented 8 years ago

Thanks for the hint @subu-cliqz , I'll look around. From the source code: -- JSON server/client -- This is a non-standard protocol, which is very handy -- to serialize data from one process to another. Each packet -- is a table, serialized as a JSON string. Each JSON string -- is separated by a \n. See examples. Not exactly sure what does that mean since I'm not very familiar with REST APIs / JSONS but'll I'll probably try different separators and see what happens.