网络编程
位置:首页>> 网络编程>> 网络编程>> Bottle部署web服务及postman接口的方法

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

作者:Chapmancp  发布时间:2022-06-14 23:38:53 

标签: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接口的方法

来源:https://blog.csdn.net/Chapmancp/article/details/112601819

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com