Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with python requests library #21

Closed
subu-cliqz opened this issue Sep 29, 2015 · 3 comments
Closed

Not working with python requests library #21

subu-cliqz opened this issue Sep 29, 2015 · 3 comments

Comments

@subu-cliqz
Copy link

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
Copy link

offbit commented Feb 17, 2016

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

@subu-cliqz
Copy link
Author

@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
Copy link

offbit commented Feb 17, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants