在页面重新加载后,Bottle REST API会生成不同的结果

时间:2013-12-11 23:44:19

标签: python rest fortran bottle

我刚刚构建了我的第一个REST API服务,但它表现得非常奇怪......当调用此REST API时,它会进行一些计算并返回结果。但是,在我的设置中,没有重新启动REST服务器,只有第一次提交的结果是正确的。自第二次提交以来,结果持续下降。以前有人有这个问题吗?

宿主

all_dic = {"APPRAT":APPRAT, "APPNUM":APPNUM, "APSPAC":APSPAC, "KOC":KOC, "METHAF":METHAF, "WETTED":WETTED,
           "METHOD":METHOD, "AIRFLG":AIRFLG, "YLOCEN":YLOCEN, "GRNFLG":GRNFLG, "GRSIZE":GRSIZE,
           "ORCFLG":ORCFLG, "INCORP":INCORP, "SOL":SOL, "METHAP":METHAP, "HYDHAP":HYDHAP, "FOTHAP":FOTHAP}

data = json.dumps(all_dic)
url='http://localhost:7777/myroute/' 
http_headers = {'Content-Type' : 'application/json'}
response = urlfetch.fetch(url=url, payload=data, method=urlfetch.POST, headers=http_headers)   
self.data_a= json.loads(response.content)["ff"]

REST服务器

from bottle import route, run, post, request
import json

@post('/myroute/') 
def myroute():
    APPRAT = request.json["APPRAT"]
    APPNUM = request.json["APPNUM"]
    APSPAC = request.json["APSPAC"]
    KOC = request.json["KOC"]
    METHAF = request.json["METHAF"]
    WETTED = request.json["WETTED"]
    METHOD = request.json["METHOD"]
    AIRFLG = request.json["AIRFLG"]
    YLOCEN = request.json["YLOCEN"]
    GRNFLG = request.json["GRNFLG"]
    GRSIZE = request.json["GRSIZE"]
    ORCFLG = request.json["ORCFLG"]
    INCORP = request.json["INCORP"]
    SOL = request.json["SOL"]
    METHAP = request.json["METHAP"]
    HYDHAP = request.json["HYDHAP"]
    FOTHAP = request.json["FOTHAP"]

    import geneec
    ff=geneec.geneec2(APPRAT,APPNUM,APSPAC,KOC,METHAF,WETTED,METHOD,AIRFLG,YLOCEN,GRNFLG,GRSIZE,ORCFLG,INCORP,SOL,METHAP,HYDHAP,FOTHAP)
    print all the inputs
    print ff
    return json.dumps({'ff':ff})

run(host='localhost', port=7777, debug=True)

其中geneec是使用FORTRAN复制到Python模块(geneec.pyd)的f2py程序。我已在本地纯Python环境中测试了这个mudule,它工作正常(多次提交后结果不会更改。) 那么有人可以就这个问题给我一些建议吗?谢谢!

更新

以下是在服务器端打印的结果。我所看到的是同一组输入产生了不同的输出

{'GRSIZE': 'a', 'APSPAC': '6', 'INCORP': 0, 'ORCFLG': 'a', 'KOC': '2', 'METHAP': '6', 'SOL': '3', 'YLOCEN': '12', 'FOTHAP'
 'AIRFLG': 'a', 'APPRAT': '4', 'METHOD': 'a', 'WETTED': 'Yes'}
(576.0662841796875, 530.255615234375, 331.788330078125, 153.9146728515625, 104.5523681640625, 'AERL_A', 8.471641540527344,
127.0.0.1 - - [11/Dec/2013 23:41:43] "POST /myroute/ HTTP/1.1" 200 150
{'GRSIZE': 'a', 'APSPAC': '6', 'INCORP': 0, 'ORCFLG': 'a', 'KOC': '2', 'METHAP': '6', 'SOL': '3', 'YLOCEN': '12', 'FOTHAP'
 'AIRFLG': 'a', 'APPRAT': '4', 'METHOD': 'a', 'WETTED': 'Yes'}
(546.4204711914062, 480.0862731933594, 245.5520477294922, 98.00833892822266, 65.50333404541016, 'AERL_A', 8.47164154052734
127.0.0.1 - - [11/Dec/2013 23:41:52] "POST /myroute/ HTTP/1.1" 200 152
{'GRSIZE': 'a', 'APSPAC': '6', 'INCORP': 0, 'ORCFLG': 'a', 'KOC': '2', 'METHAP': '6', 'SOL': '3', 'YLOCEN': '12', 'FOTHAP'
 'AIRFLG': 'a', 'APPRAT': '4', 'METHOD': 'a', 'WETTED': 'Yes'}
(535.4012451171875, 458.6314392089844, 213.1800079345703, 81.3574447631836, 54.282127380371094, 'AERL_A', 8.47164154052734
127.0.0.1 - - [11/Dec/2013 23:41:58] "POST /myroute/ HTTP/1.1" 200 152
{'GRSIZE': 'a', 'APSPAC': '6', 'INCORP': 0, 'ORCFLG': 'a', 'KOC': '2', 'METHAP': '6', 'SOL': '3', 'YLOCEN': '12', 'FOTHAP'
 'AIRFLG': 'a', 'APPRAT': '4', 'METHOD': 'a', 'WETTED': 'Yes'}
(530.4227294921875, 448.1323547363281, 198.46009826660156, 74.41312408447266, 49.63011932373047, 'AERL_A', 8.4716415405273
127.0.0.1 - - [11/Dec/2013 23:42:04] "POST /myroute/ HTTP/1.1" 200 153

1 个答案:

答案 0 :(得分:1)

我怀疑这与REST调用本身有关,因为您正在打印出相同的输入。我会研究一下geneec2在做什么。您可以测试REST调出,并将所有参数设置为默认值(而不是请求信息),然后查看是否可以修复任何内容。如果这不会产生一致的结果,那么你需要用一堆打印语句重新编译geneec2,看看是否能让你更好地了解出现了什么问题。