使用外部API访问时,Python Bottle API没有Json响应


Python Bottle API No Json Response while accessing using external API

我使用bottle为openerp创建了一个api,运行良好。

每当我使用浏览器访问时

例如:http://example.com/api/user_name=uname&密码=pwd

它返回json值,并在使用python 访问同一api时进行响应

但问题是,当我使用php从外部api访问它时,它不会响应或返回json数据。

这是我的wgsi代码

    from bottle import Bottle,get,post,run,request,error,route,template,validate,debug,response
    import json
    import os
    import sys
    import bottle
    @route ('/user_name=:user_name&password=:password', method='GET')
    @route ('/user_name=:user_name&password=:password', method='POST')
    def login_validate(user_name,password):
        import xmlrpclib
        print "test"
        dbname = 'more'
        sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')
        uid = sock_common.login(dbname, user_name, password)
        if uid:
            sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
            adv_fields = ['name']
            adv_args=[('user_id','=',uid)]
            adv_id = sock.execute(dbname, uid, password, 'res.partner', 'search', adv_args) 
            if adv_id:
                res = sock.execute(dbname, uid, password, 'res.partner', 'read',adv_id, adv_fields) [0]
                print res,type(res)
                return json.dumps({'Sucesss':res['name']})
            else:
                return json.dumps({'Error':'User Found but not a partner'})
        else:
            return json.dumps({'Failure':'Invalid User Name or Password'})
    application = bottle.default_app()

第一选择:禁用Apache gzip压缩

请参阅Include mods-enabled/*.loadInclude mods-enabled/*.conf,检查mods-enabled文件夹中是否有对mod_deflate(Apache的gzip会话)的引用。

如果你在一个类似Debian的系统上,你可以用这个禁用它:

a2dismod deflate
service apache2 restart

如果您使用的是RedHat/Centos,请选中/etc/httpd/conf/httpd.conf并编辑LoadModule行。

第二选择:读取gzip响应

解压缩gzip压缩的http响应