Python -Anfragen in einer API, Pagination spart nur die letzte IterationPython

Python-Programme
Anonymous
 Python -Anfragen in einer API, Pagination spart nur die letzte Iteration

Post by Anonymous »

Ich habe diesen Code unten und verwende Anforderungen in eine API: < /p>

Code: Select all

import requests

def Sults():
headers = {
"Authorization":"xxxxxxxxxxxxxxxxxxxxxxxx",
"Content-Type":"application/json;charset=UTF-8"
}
global id
id = []
for count1 in range(3):
url = "https://api/api/v1/implantacao/projeto?&start={}&dtInicio=2022-01-01T18:02:55Z".format(count1)
response = requests.get(url, headers=headers)
data = response.json()
url2 = "https://api/api/v1/implantacao/projeto?&dtInicio=2022-01-01T18:02:55Z&concluido=false"
response2 = requests.get(url2, headers=headers)
data2 = response2.json()
url3 = "https://api/api/v1/implantacao/projeto?&dtInicio=2022-01-01T18:02:55Z&concluido=true"
response3 = requests.get(url3, headers=headers)
data3 = response3.json()

#   print(data)
ids = unidades(data)
print(ids)
ids2 = unidades2(data2)
print(ids2)
ids3 = unidades3(data3)
print(ids3)

def unidades(data):
for i in data['data']:
id.append(i['id']) #append id list
return id

def unidades2(data2):
id_exclude = []
for j in data2['data']:
id_exclude.append(j['id'])
return id_exclude

def unidades3(data3):
id_conclude = []
for k in data3['data']:
id_conclude.append(k['id'])
return id_conclude

if __name__ == '__main__':
Sults()

In die Zeile: url = "https: /// api/v1/implantacao/projeto? Das Problem ist, dass der Code, wenn ich versuche, die ID aus jeder Schleife in die DE -Liste zu speichern: ID = [], in diesem Fall nur die letzte Schleife, in diesem Fall, 3 (Thrid -Seite der Schleife in 0,1,2). < /P>
Zum Beispiel: "https: // api/api/v1/Implantacao/projeto? 147, 149, 150, 151, 153, 154, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233]
url = "https: // api/api/v1/Implantacao/projeto? 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266. case page 0 and page 1) : [122, 123, 124, 125, 126, 127, 129, 132, 133, 134, 135, 137, 138, 140, 144, 145, 146, 147, 149, 150, 151, 153, 154, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190. 211, 212. 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271]

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post