简体   繁体   中英

json decode exception python


Sample server

I have a python script as mentioned below copied to /var/www/cgi-bin folder with permissions set to 775.

#!/usr/bin/env python

 print "Content-type: text/plain\n\n";
print "testing...\n";

import cgitb; cgitb.enable()
import cgi

from jsonrpc import handleCGI, ServiceMethod
import json
from datetime import datetime

@ServiceMethod
def echo():
    return "Hello"

if __name__ == "__main__":
    handleCGI()

Sample Client

Now, Iam accessing this simple echo service using the below client code.

from jsonrpc import ServiceProxy
import json

s = ServiceProxy(`"http://localhost/cgi-bin/t2.py"`)
print s.echo()

1/ Iam getting the below error when i run the above client. Any thoughts? 2/ Is there any issue with httpd.conf settings?

File "/usr/lib/python2.7/site-packages/jsonrpc/proxy.py", line 43, in __call__
    resp = loads(respdata)
  File "/usr/lib/python2.7/site-packages/jsonrpc/json.py", line 211, in loads
    raise JSONDecodeException('Expected []{}," or Number, Null, False or True')
jsonrpc.json.JSONDecodeException: Expected []{}," or Number, Null, False or True

Note: Iam using the example mentioned at the below link using cgi way of handling json.

http://json-rpc.org/wiki/python-json-rpc

Please let me know.

Thanks! Santhosh

I know this is super late, but I found this question when I had the same problem. In hopes it helps someone else, I will post my solution.

In my case it was as simple (stupid) as making the python file itself executable. ie chmod 755 t2.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM