python使用OPTIONS ,delete方式请求接口

刚学习了python使用OPTIONS ,delete方式请求接口,跟大家分享下。(ps,我也是踩了不少的坑)
下面代码是一个删除并确定的步骤

import urllib.request
import requests
import json
def getlist():
    url="http://test-**************ink:8803/api/pc/collectFile/list"
    host={
     "X-Token":"********",
          "Content-Type":"application/json;charset=UTF-8"
          }
    date={
     "page":1,"pageSize":10,"keyWords":"","isPassword":0}
    #因为要删除的链接中有list查询出的参数作为后缀,并且因为有分页,所以要创建循环
    #创建控制器
    kongzhi=0
    #判断控制器,这里是死循环
    while kongzhi==0:
    	#请求数据,
        response = requests.post(url, json=date, headers=host)
        res = response.json()
        data = res["data"]
        records = data["records"]
        #判断是否删除完毕
        if len(records)!=0:
            for  a in range (len(records)):
                #得到的参数作为后缀
                uuid=records[a]["uuid"]
                print(uuid)
                detail(uuid)
        #删除完毕则跳出循环 while        
        elif len(records)==0:
            print("删除完毕")
            break
def detail(uuid):
    url="http://test-*********:8803/api/pc/collectFile/detail/"+uuid
    host = {
     "X-Token": "***********",
            "Content-Type": "application/json;charset=UTF-8"}
    #调用删除询问,OPTIONS 不是直接为请求方式,而是通过get,post转化而来(按场景),因为OPTIONS 不会反回数据,不懂请百度OPTIONS 请求方式 
    response = requests.get(url,headers=host)
    res = response.json()
    print(res)
    delete(uuid)
def  delete(uuid):
    url="http://test-************8803/api/pc/collectFile/delete/"+uuid
    host = {
     "X-Token": "***********"}
    #调用删除,因为请求询问是异步的,返回的是可请求方式
    #刚好返回的请求方式中有delete
    response = requests.delete(url,headers=host)
    res = response.json()
    print(res)
 
class mian():
    getlist()

你可能感兴趣的:(python,python)