【发布时间】:2020-04-08 12:18:01
【问题描述】:
我是 python 新手,所以这似乎是一个非常愚蠢的问题,请多多包涵。
我正在使用以下代码: (如果还附上调试图像)
for connector in la_details['properties']['parameters']['$connections']['value']:
if connector['connectionName'] in allowed_connectors:
result = True
现在,它不是在 'connector' 变量中获取 'dict' 值,而是获取一个 'string',因此 'if' 语句给出了错误:
string indices must be integers
有人可以指导我如何获取“dict”值而不是“string”吗?我试图用谷歌搜索,但找不到任何与这种情况相匹配的东西,可能是因为我使用了错误的术语。
编辑:print(la_details) 产生以下输出:
{u'name': u'REDACTED',
u'tags': {},
u'id': u'/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Logic/workflows/REDACTED',
u'location': u'REDACTED',
u'type': u'Microsoft.Logic/workflows',
u'properties': {u'definition': {u'parameters': {u'$connections': {u'defaultValue': {}, u'type': u'Object'}}, u'triggers': {u'Recurrence': {u'recurrence': {u'frequency': u'Month', u'interval': 1}, u'type': u'Recurrence'}}, u'outputs': {}, u'actions': {u'Send_an_email_(V2)': {u'inputs': {u'body': {u'Body': u'<p>TEST</p>', u'To': u'REDACTED', u'Subject': u'TEST'}, u'path': u'/v2/Mail', u'host': {u'connection': {u'name': u"@parameters('$connections')['office365']['connectionId']"}}, u'method': u'post'}, u'runAfter': {}, u'type': u'ApiConnection'}, u'Get_tables_(V2)': {u'inputs': {u'path': u"/v2/datasets/@{encodeURIComponent(encodeURIComponent('default'))},@{encodeURIComponent(encodeURIComponent('default'))}/tables", u'host': {u'connection': {u'name': u"@parameters('$connections')['sql']['connectionId']"}}, u'method': u'get'}, u'runAfter': {u'Send_an_email_(V2)': [u'Succeeded']}, u'type': u'ApiConnection'}}, u'contentVersion': u'1.0.0.0', u'$schema': u'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#'}, u'version': u'REDACTED', u'parameters': {u'$connections': {u'value': {u'office365': {u'connectionId': u'/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/connections/office365', u'id': u'/subscriptions/REDACTED/providers/Microsoft.Web/locations/eastus/managedApis/office365', u'connectionName': u'office365'}, u'sql': {u'connectionId': u'/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/connections/sql', u'id': u'/subscriptions/REDACTED/providers/Microsoft.Web/locations/eastus/managedApis/sql', u'connectionName': u'sql'}}}}, u'integrationServiceEnvironment': {u'type': u'Microsoft.Logic/integrationServiceEnvironments', u'name': u'ise-demo-res', u'id': u'/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Logic/integrationServiceEnvironments/ise-demo-res'}, u'endpointsConfiguration': {u'connector': {u'outgoingIpAddresses': [{u'address': u'40.71.11.80/28'}, {u'address': u'REDACTED'}, {u'address': u'REDACTED'}, {u'address': u'REDACTED'}, {u'address': u'REDACTED'}, {u'address': u'REDACTED'}, {u'address': u'REDACTED'}, {u'address': u'REDACTED'}, {u'address': u'REDACTED'}]}, u'workflow': {u'outgoingIpAddresses': [{u'address': u'REDACTED'}, {u'address': u'REDACTED'}], u'accessEndpointIpAddresses': [{u'address': u'REDACTED'}]}}, u'state': u'Enabled', u'accessEndpoint': u'REDACTED', u'createdTime': u'2020-03-12T14:45:34.6908438Z', u'changedTime': u'2020-04-08T10:35:32.3388762Z', u'provisioningState': u'Succeeded'}}
【问题讨论】:
-
能否在您的问题中添加 la_details 的打印件
-
添加了 la_details 的打印。
标签: python dictionary iteration