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

网络编程 2021-07-05 13:20www.168986.cn编程入门
这篇文章主要介绍了Bottle部署web服务及postman接口的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

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接口内容请搜索狼蚁SEO以前的文章或继续浏览狼蚁网站SEO优化的相关文章希望大家以后多多支持狼蚁SEO!

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by