Get data from API and be careful of circulation in Python

Today I need to get data from existing API and show it on my website

yesterday I searched the answer is Django Rest, but after several trials I found it more like a create API tool, And then I found another tool which saved my day

pip install requests

Python is a really simple and easy tool with a lot of useful models

after getting my data, you need to handle them to do what you need and here is a useful one I need to remenber

import requests

import json

r= requests.get('http://10.75.10.254/getdeviceinfo.php')

line= r.text

obj = json.loads(line)

i = 0

while i < len(obj):

print(obj[i]['nickname'])

i=i+1

cut json into string and use it

and circulation items in Python is much different from other languages need to be really careful

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 换行 智能换行 Shift + Enter 窗口间切换 在窗口间进行切换 Ctrl + Tab
    一曲广陵散阅读 224评论 0 0
  • 河流一点不着急 关键时刻 干脆停下来 一动不动 风从故乡来 却拼命唱 《一路向北》 雁越飞越高 氧气越来越少 逆向...
    静听旁白阅读 205评论 0 1
  • 我和先生结婚十年。我们有着各自不同的工作与朋友圈,生活逐渐变得平淡却也平稳。都说婚姻有七年之痒。我庆幸我的婚姻过了...
    李慧芳阅读 253评论 4 2
  • 突然忘了窗外时光流散的声音 那一年我基督式的降临 开始了人生的思考 二十多年的喜怒哀乐 怪诞的充实着我的生活 一切...
    诗人不留泪阅读 335评论 2 1