网络编程 
首页 > 网络编程 > 浏览文章

Bottle部署web服务及postman接口的方法

(编辑:jimmy 日期: 2024/5/19 浏览:3 次 )

Bottle是一个快速、简洁、轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除了Python的标准库外,其不依赖任何其他模块。

from bottle import route, request, run
import requests
import cv2
import numpy as np
 
@route('/testimg',method='POST')#
def testimg():
 try:
  #获取对应params值
  result = {}
  result["name"] = request.query.name#
  result["nums"] = request.query.nums
  
  #获取json对应内容
  #print(request.json)
  urllist = request.json["urllist"]
  #print(type(urllist))
  #print(urllist)
  imgPath = []
  for i in range(len(urllist)):
   imgPath.append(urllist[i])
 
  for i in range(len(imgPath)):
   #print(imgPath[i])
   #基于url获取数据
   rev = requests.get(imgPath[i], verify=False) # , timeout=config.timeout
   img = cv2.imdecode(np.frombuffer(rev.content, np.uint8), cv2.IMREAD_COLOR) # 直接解码网络数据,获得bgr图片
  rec = 0
   
  return str(rec)
 except BaseException as e:
  logger.exception(e)
  return str(0)
 
if __name__ == "__main__":
 
 run(host='172.17.0.2', port=49166, debug=False)

postman接口测试。

params传递参数。

body传递json等文本数据。

Bottle部署web服务及postman接口的方法

Bottle部署web服务及postman接口的方法

上一篇:关于idea+centos7+zookeeper报错connectionloss,timeout问题
下一篇:使用postman进行接口测试的方法(测试用户管理模块)
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。