需要有一个带有列表的 for 循环,以用作 get 请求中的参数
我有以下项目列表,其中每个项目都有一个 ID,
List_Item = [['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:471b2fd7-d1f6-4fdd-a701-8d2426e2c67b'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:fe43ed8e-1254-4bf3-a6d1-be4568861ce7'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:4ac881c8-942d-4bf2-8728-61ee8db55e74'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:24fa0bf7-af38-46aa-99c7-5d74a66e4132'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:fd9f6f71-9e39-4777-8d99-80f3b0d9e314'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:7fee75ec-5ed7-4542-b62f-adb6879d7d35'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:51e5e086-91bd-411f-9987-46cb7376fd76'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:8a664472-45fb-45ce-9965-2087638635f6'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:e4d01008-4d15-4d64-825a-d17594a00d82'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:b76272c1-a295-4b0d-b67c-a6345ac066c3'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:7a767269-d0d9-4ce6-a655-355173778141'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:5f93f6d9-c0ce-4006-84bf-217cdab64fce'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:8d062331-77b9-4c5e-87d6-2e02adaf672c'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:fb63787e-f5a5-4d4b-b637-99d8354fc482'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:dc51d14f-cfcd-4688-a8f0-fea6129d77d1'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:f65ece95-6cb8-4ef9-99b3-28067af26b10'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:74588a7a-549f-4e07-a018-557fd8e9749c']
]
我想在下面的脚本中使用此 id 列表作为参数。我想这样做的原因是因为为了访问与DataProcessingITem相关的信息,我需要给出DataProcessing的id,以便代码了解它需要搜索哪些信息并返回信息。
这里的目的是使用 id 作为参数,以便获取此研究信息。棘手的是我需要对已存储在列表中的几个 id 执行此操作。
有人知道如何实现这一目标吗?
for categoryItem in structureDictItem:
for endpointItem in structureDictItem[categoryItem]:
endpointFilenameItem = endpointItem
if categoryItem in ["types"]:
endpointFilenameItem = endpointItem.replace("/", "_")
url = DataGalaxy_url + endpointItem
params = {"versionId":Workspace_id,
"includeAccessData":"true",
"includeAttributes":"true",
"includeLinks":"true",
"limit":5000
}
jsonResponse = requests.get(url, params=params, headers={"Authorization":accessToken}).json()
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
try:
jsonResponsePages = jsonResponse['pages']
if int(jsonResponsePages) != 1:
for i in range(2, jsonResponsePages+1, 1):
for x in range(0,30):
params["page"] = str(i)
params["dataProcessingId"] = List_Item[x]
jsonResponse = requests.get(url=url, params = params, headers={"Authorization":accessToken}).json()['results']
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
except:
print(endpointItem)
next
我尝试了以下脚本,但它告诉我 dataProcessingId 必须是一个字符串
for categoryItem in structureDictItem:
for endpointItem in structureDictItem[categoryItem]:
endpointFilenameItem = endpointItem
if categoryItem in ["types"]:
endpointFilenameItem = endpointItem.replace("/", "_")
url = DataGalaxy_url + endpointItem
params = {"versionId":Workspace_id,
"includeAccessData":"true",
"includeAttributes":"true",
"includeLinks":"true",
"limit":5000
}
jsonResponse = requests.get(url, params=params, headers={"Authorization":accessToken}).json()
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
try:
jsonResponsePages = jsonResponse['pages']
if int(jsonResponsePages) != 1:
for i in range(2, jsonResponsePages+1, 1):
for x in range(0,30):
params["page"] = str(i)
params["dataProcessingId"] = List_Item[x]
jsonResponse = requests.get(url=url, params = params, headers={"Authorization":accessToken}).json()['results']
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
except:
print(endpointItem)
next
I have the following List of Item with for each of them an ID
List_Item = [['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:471b2fd7-d1f6-4fdd-a701-8d2426e2c67b'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:fe43ed8e-1254-4bf3-a6d1-be4568861ce7'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:4ac881c8-942d-4bf2-8728-61ee8db55e74'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:24fa0bf7-af38-46aa-99c7-5d74a66e4132'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:fd9f6f71-9e39-4777-8d99-80f3b0d9e314'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:7fee75ec-5ed7-4542-b62f-adb6879d7d35'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:51e5e086-91bd-411f-9987-46cb7376fd76'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:8a664472-45fb-45ce-9965-2087638635f6'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:e4d01008-4d15-4d64-825a-d17594a00d82'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:b76272c1-a295-4b0d-b67c-a6345ac066c3'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:7a767269-d0d9-4ce6-a655-355173778141'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:5f93f6d9-c0ce-4006-84bf-217cdab64fce'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:8d062331-77b9-4c5e-87d6-2e02adaf672c'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:fb63787e-f5a5-4d4b-b637-99d8354fc482'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:dc51d14f-cfcd-4688-a8f0-fea6129d77d1'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:f65ece95-6cb8-4ef9-99b3-28067af26b10'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:74588a7a-549f-4e07-a018-557fd8e9749c']
]
I would like to use this list of id in my script below as a parameter. The reason I want to do this is because in order to have access to information related to DataProcessingITem, I need to give the id of DataProcessing in order for the code to understand which information it needs to search for and brings back the information.
The purpose here is to use the id as a parameter in order to get this researched information. The tricky thing is that I need to do it for several id that have been stored in a list.
Someone has an idea how to achieve that?
for categoryItem in structureDictItem:
for endpointItem in structureDictItem[categoryItem]:
endpointFilenameItem = endpointItem
if categoryItem in ["types"]:
endpointFilenameItem = endpointItem.replace("/", "_")
url = DataGalaxy_url + endpointItem
params = {"versionId":Workspace_id,
"includeAccessData":"true",
"includeAttributes":"true",
"includeLinks":"true",
"limit":5000
}
jsonResponse = requests.get(url, params=params, headers={"Authorization":accessToken}).json()
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
try:
jsonResponsePages = jsonResponse['pages']
if int(jsonResponsePages) != 1:
for i in range(2, jsonResponsePages+1, 1):
for x in range(0,30):
params["page"] = str(i)
params["dataProcessingId"] = List_Item[x]
jsonResponse = requests.get(url=url, params = params, headers={"Authorization":accessToken}).json()['results']
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
except:
print(endpointItem)
next
I have tried something witht the following script but it told me that dataProcessingId must be a string
for categoryItem in structureDictItem:
for endpointItem in structureDictItem[categoryItem]:
endpointFilenameItem = endpointItem
if categoryItem in ["types"]:
endpointFilenameItem = endpointItem.replace("/", "_")
url = DataGalaxy_url + endpointItem
params = {"versionId":Workspace_id,
"includeAccessData":"true",
"includeAttributes":"true",
"includeLinks":"true",
"limit":5000
}
jsonResponse = requests.get(url, params=params, headers={"Authorization":accessToken}).json()
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
try:
jsonResponsePages = jsonResponse['pages']
if int(jsonResponsePages) != 1:
for i in range(2, jsonResponsePages+1, 1):
for x in range(0,30):
params["page"] = str(i)
params["dataProcessingId"] = List_Item[x]
jsonResponse = requests.get(url=url, params = params, headers={"Authorization":accessToken}).json()['results']
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
except:
print(endpointItem)
next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
List_Item
是一个列表列表,因此当您执行List_Item[int]
时,它会返回另一个列表您需要获取列表内的字符串:
此外,而不是使用范围函数循环列表,您可以像这样循环列表:
List_Item
is a list of lists, so when you doList_Item[int]
, it is returning another listYou need to get the string inside the list:
In addition, instead of using a range function to loop over the list, you can just loop over the list like: