Unable to iterate over the entire results of policy_states.list_query_results_for_subscription.
See original GitHub issue- Package Name: azure.mgmt.policyinsights
- Package Version: 1.0.0
- Operating System: MacOS
- Python Version: 3.7
Describe the bug The issue happens when trying to list the policy state of entire subscription.
After instantiating PolicyInsightsClient and iterating over the results returned by client.policy_states.list_query_results_for_subscription(...), the following exception is thrown
File "/Users/ashishg/****/venv/lib/python3.7/site-packages/azure/mgmt/policyinsights/operations/_policy_states_operations.py", line 352, in get_next
raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: (HttpMethodNotSupported) The http method 'GET' is not supported for 'queryResults'.
Only the first 1000 policy state results are listed and when the client goes on to fetch the next 1000 results it errors out with the above exception.
The issue is happening because the Policy States List API (https://docs.microsoft.com/en-us/rest/api/policy/policystates/listqueryresultsforsubscription) expects the URL returned by @odata.nextLink attribute to be called over POST and not GET.
The problem seems to in line, https://github.com/Azure/azure-sdk-for-python/blob/447e6f766ac809b95bac65e72752c44a59ea073f/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_states_operations.py#L139
Things start to work, on changing the line from request = self._client.get(url, query_parameters, header_parameters)
to
request = self._client.post(url, query_parameters, header_parameters)
To Reproduce Steps to reproduce the behavior:
pip install azure-mgmt-policyinsights(latest version which is 1.0.0)- Run the following simple snippet to reproduce the issue. NOTE: Make sure that the subscription this is tried upon has more than 1000 policy state results.
from azure.mgmt.policyinsights._policy_insights_client import PolicyInsightsClient
#credential = <Create the credential object here>
#sub_id = <some subscription id>
client = PolicyInsightsClient(cred, base_url=mavlink_helpers.get_arm_base_url(tenant_region), subscription_id=sub_id)
policy_states = client.policy_states.list_query_results_for_subscription(policy_states_resource="latest",
subscription_id=sub_id)
for policy_state in policy_states:
policy_state = policy_state.as_dict()
print(policy_state['policy_definition_id'], policy_state['resource_id'])
Expected behavior One should be able to iterate over the entire list of policy states.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)

Top Related StackOverflow Question
This issue happened because next link using wrong method. Normally, next_link will use
getto get next page. But this API uses an unusualpostrequest to get data. https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_states_operations.py#L139Hi, we’re sending this friendly reminder because we haven’t heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don’t hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!