简体   繁体   English

json解码异常python

[英]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. 我将如下所述的python脚本复制到/ var / www / cgi-bin文件夹,并将权限设置为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. 现在,Iam使用以下客户端代码访问此简单的回显服务。

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. 1 /我在运行上述客户端时收到以下错误。 Any thoughts? 有什么想法吗? 2/ Is there any issue with httpd.conf settings? 2 / httpd.conf设置是否有问题?

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. 注意:Iam使用以下链接中提到的示例,使用cgi处理json的方式。

http://json-rpc.org/wiki/python-json-rpc 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. 就我而言,这就像使python文件本身可执行一样简单(愚蠢)。 ie chmod 755 t2.py 即chmod 755 t2.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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