dongmu5920 2013-07-01 11:56
浏览 124

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

I created an api for openerp using bottle and works fine.

Whenever i access using browser

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

it returns json value and also responds while accessing same api using python

But the problem is while i access it from external api using php it doesn't response or returns json data.

here is my wgsi code

    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()
  • 写回答

1条回答 默认 最新

  • dream02008 2013-07-05 13:17
    关注

    1st choice: Disable Apache gzip compression

    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).

    If you are on a Debian like system you may disable it with this:

    a2dismod deflate
    service apache2 restart
    

    If you are on RedHat/Centos then check /etc/httpd/conf/httpd.conf and edit the LoadModule lines.

    2nd choice: Read gzip response

    Uncompress gzip compressed http response

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。