1

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()
Senthilnathan
  • 790
  • 9
  • 27

1 Answers1

1

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

Community
  • 1
  • 1
MGP
  • 2,981
  • 35
  • 34
  • Actually the problem is with the php developer's json he uses 'JSON' instead of 'JSONp'.After i checked his code, i found the problem is on his side check this one for details http://stackoverflow.com/questions/2887209/what-are-the-differences-between-json-and-jsonp – Senthilnathan Dec 05 '13 at 06:39