我創建了一個使用瓶子的openerp API,並且工作正常。Python Bottle API使用外部API訪問時沒有Json響應
每當我訪問使用瀏覽器
例如:http://example.com/api/user_name=uname&password=pwd
返回JSON值,也同時使用python
訪問相同的API響應但問題是,當我使用外部API訪問PHP它不響應或返回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()
你可以張貼一些調試信息?參數是否正確發送?某些'print(user_name,password)'可能有幫助。 –
訪問使用PHP內容類型不返回作爲JSON它返回作爲gzip – senthilnathang
你到底如何部署此應用程序?涉及哪個Web服務器?似乎gzip發生在wsgi之後,即:nginx,apache .. –