qiq2005 2015-03-23 19:54 采纳率: 0%
浏览 2175

如何用python web.py web service 做 多重参数的 服务?

大家好。我用了python 的 web.py做了一个 web service

install web.py
cd webpy
编辑python web service.

#!/usr/bin/env python

urls = ('/title_matching2','title_matching2')
app = web.application(urls,globals())

class title_matching2:
def init(self):
self.hello = "hello world"

def GET(self):
   getInput = web.input(name="World")

   processing the data, return the hash table, I wanted




       return gg

   if __name__ == "__main__":
    app.run()

然后 run 这个 web service , ./some.py, 再call:

links http://localhost:8080/title_matching2?title=diehard

会返回一个hash table. 正是我想要的。

但是如果run multiple parameters 的话:

代码如下:

usr/bin/env python

urls = ('/title_matching4','title_matching4')
app = web.application(urls,globals())




class title_matching4:
    def __init__(self):
        self.hello = "hello world"

    def GET(self):
       getInput = web.input(title="World",prod="type")

   title1=str(getInput.title)
   prod1=str(getInput.prod)
   processing the data, return the hash table I wanted.

   return qq

if name == "__main__":
app.run()

然后再run ./rest9.py
再打开一个link:

links http://localhost:8080/title_matching4?title=diehard&prod=feature
就没有hash table 返回。虽然我想返回hash table.

只是出现如下东西在screen 上:

ubuntu@ip-10-0-0-126:~$ links http://localhost:8080/title_matching4?title=diehard&prod=feature
[1] 1190
请问这是为什么?
为什么不能打开一个连接,并有hash table 返回?

多谢!

  • 写回答

1条回答

  • qiq2005 2015-03-25 02:31
    关注

    大家好。

    我后来又找到一个可以做query的package 叫flask.也是在python 里。

    用它写了一个multiple parameters 的query,差不过如下:

    http://stackoverflow.com/questions/15182696/multiple-parameters

    还是用links 打开一个网页

    links http://127.0.0.1:5000/api?name=XXX&prod=XXX

    没有回应。只是出现一个随机数,在screen上。

    但是用curl就能返回想要的东西:

    curl -XGET 'http://127.0.0.1:5000/api?name=XXX&prod=XXX'

    而且用curl -XGET作用在以前用web.py的东西上也能得到想要的。但是,只是在screen
    上显示一堆东西。并不是打开网页。

    请问这是为什么?就是说用curl,不管怎样都能返回想要的东西,用links 不管怎样都
    不能返回想要的东西。这样一来只要curl能跑出来东西,是不是就成了?

    多谢!

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序