简体   繁体   English

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

[英]Python Bottle API No Json Response while accessing using external API

I created an api for openerp using bottle and works fine. 我使用瓶子为openerp创建了一个api,并且工作正常。

Whenever i access using browser 每当我使用浏览器访问时

for example : http://example.com/api/user_name=uname&password=pwd 例如: http : //example.com/api/user_name=uname&password=pwd

it returns json value and also responds while accessing same api using python 它返回json值,并且在使用python访问相同的api时也会响应

But the problem is while i access it from external api using php it doesn't response or returns json data. 但是问题是当我使用php从外部api访问它时,它没有响应或返回json数据。

here is my wgsi code 这是我的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()

1st choice: Disable Apache gzip compression 第一种选择:禁用Apache gzip压缩

See Include mods-enabled/*.load and Include mods-enabled/*.conf , check inside mods-enabled folder to see if there's any reference to mod_deflate (Apache's gzip comrpession). 请参阅Include mods-enabled/*.load Include mods-enabled/*.conf 。load和Include mods-enabled/*.conf ,在mods-enabled文件夹中检查是否有对mod_deflate的引用(Apache的gzip comrpession)。

If you are on a Debian like system you may disable it with this: 如果您使用的是类似Debian的系统,则可以使用以下方法禁用它:

a2dismod deflate
service apache2 restart

If you are on RedHat/Centos then check /etc/httpd/conf/httpd.conf and edit the LoadModule lines. 如果您在RedHat / Centos上,请检查/etc/httpd/conf/httpd.conf并编辑LoadModule行。

2nd choice: Read gzip response 第二选择:阅读gzip回应

Uncompress gzip compressed http response 解压缩gzip压缩的HTTP响应

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

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