简体   繁体   English

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

[英]Bottle REST API generates different results after page reloading

I just built my first REST API service, but it behaved weirdly... When this REST API is called, it does some calculation and returns the results. 我刚刚构建了我的第一个REST API服务,但是它的行为很奇怪...当调用此REST API ,它会进行一些计算并返回结果。 However, in my setup, without restarting the REST server, only the first time submission's result is correct. 但是,在我的设置中,无需重新启动REST服务器,只有第一次提交的结果是正确的。 Results keep declining since the second submission. 自第二次提交以来,结果一直在下降。 Has anyone had this issue before? 有人遇到过这个问题吗?

host 主办

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

Where geneec is a FORTRAN program copiled into a Python module (geneec.pyd) using f2py . 其中geneec是FORTRAN copiled成使用Python模块(geneec.pyd)程序f2py I have tested this mudule in a pure Python environment locally and it works fine (results will not be changed after multiple submissions.) So can anyone give me some suggestions on this issue? 我已经在本地的纯Python环境中测试了这种混淆,并且效果很好(多次提交后结果不会更改。)那么有人可以给我一些关于此问题的建议吗? Thanks! 谢谢!

Update 更新

Below are the results print on the server end. 下面是在服务器端打印的结果。 What I have seen is the same set of inputs generated different outputs 我所看到的是同一组输入生成了不同的输出

{'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

I doubt this is related to the REST call itself, since you are getting the same inputs printed out. 我怀疑这与REST调用本身有关,因为您将打印出相同的输入。 I would look into what geneec2 is doing itself. 我会研究一下geneec2在做什么。 You could test the REST call out with all of the parameters set to default values (and not the request information) and then see if this fixes anything. 您可以将所有参数设置为默认值(而不是请求信息)来测试REST调用,然后查看它是否可以解决任何问题。 If that doesn't produce consistent results then you will need to recompile geneec2 with a bunch of print statements and see if that gives you a better idea of what is going wrong. 如果那不能产生一致的结果,那么您将需要使用一堆打印语句重新编译geneec2,并查看是否可以更好地了解出了什么问题。

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

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