python中bottle模块的使用


1.简介

2.示例

2.1一个简单的bottle接口

 1 # -*- coding: utf-8 -*-
 2 
 3 from bottle import route, request, run
 4 import json
 5 
 6 feedbackdata = {'status': 'ok', 'data': 'I received the value'}
 7 
 8 
 9 @route('/getmsg')
10 def start():
11     radar = int(request.query.radar)
12     station = int(request.query.station)
13     print 'radar and station is: ', radar, station
14     print type(radar)
15     if radar == 4 and station == 1:
16         return json.dumps(feedbackdata)
17 
18 run(host='127.0.0.1', port=8080, debug=False)

2.2通过requests获取值

1 # -*- coding: utf-8 -*-
2 
3 import requests
4 # 通过url传递的参数
5 payload = {'radar': 4, 'station': 1}
6 r = requests.get('http://127.0.0.1:8080/getmsg', params=payload)
7 print r.json()
8 print r.content
9 print r.text

!!!

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM