pythonapi接⼝post请求_python3中调⽤post和get接⼝⽤了很多⽅法都没有这个实⽤
POST API接⼝:
import json
import requests
if __name__ == '__main__':ast是什么氨基酸
url = "127.0.0.1:9001/rsa/set_uplod"
headers = {'content-type': 'application/json'}
requestData = {"certificate_no": "56565656565656", "auth_code": "123456"}
ret = requests.post(url, json=requestData, headers=headers)
printf输出格式java
if ret.status_code == 200:html常用标签及含义
text = json.)
print(text)
get API 接⼝:
import json
编程语言哪个最难学import requests
if __name__ == '__main__':
url = "127.0.0.1:9001/getSha1Test?
message=APP000051527151133935949D49FDC0A86605313931B9BB9A4C87" ret = (url)
if ret.status_code == 200:
text = json.)
print(text)
想要调⽤JSON接⼝。
则使⽤如下代码实现:
# #coding:utf-8
import json
import urllib2
#若果只需要获取⼀个接⼝的数据
url = r'api.douban/v2/book/1220563'
#访问⽹页
stacking blocks玩具response = urllib2.urlopen(url)
#json解析
html = json.ad())
#打印所需数据,我这⾥只打印了书名
python请求并解析json数据print "题⽬:","《",html['title'],"》"
输出:
题⽬: 《 从胎教开始 》
1
当然如果你想获取多个JSON数据,加个循环就可以了:
# #coding:utf-8
import json
import urllib2
#参数我是随便加的,只要符合⽹址规则就⾏
for i in range(1220564,1220580):
#url地址
url = 'api.douban/v2/book/'
#将参数转化为字符串,⽅便组装url
values = str(i)
#进⾏参数封装
url = url + values
#访问完整url
response = urllib2.urlopen(url)
#读取⽹页内容
html = json.ad())
#打印所需数据
print
print "出版⽇期:",html['pubdate']
print "概述:",html['summary']
print "作者:",html['author'][0]
print "价格:",html['price']
print "---------------------------------------------------"
i = i + 1
————————————————

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。