• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
火磷
Memory will fade,but not notes.
博客园    首页    新随笔    联系   管理    订阅  订阅
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

!!!

 

posted on 2017-12-21 17:08  火磷  阅读(4611)  评论(1)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3