GearPlug / microsoftgraph-python

Microsoft Graph API wrapper written in Python
MIT License
96 stars 40 forks source link

Bad Request on paginated response when specifying query parameters, like "$top" #26

Closed Disruption closed 2 years ago

Disruption commented 2 years ago

If you run a request specifying, for example, the $top parameter, it will fail if it needs to fetch a second page, with the following error:

microsoftgraph.exceptions.BadRequest: {'error': {'code': 'BadRequest', 'message': "Query option '$top' was specified more than once, but it must be specified at most once.", 'innerError': {'date': '2022-02-18T23:21:56', 'request-id': 'ae804f84-62aa-4bb4-a521-8c5ad8be2ed7', 'client-request-id': 'ae804f84-62aa-4bb4-a521-8c5ad8be2ed7'}}}

The reason for this error is that, when we want to fetch the next page, we use "@odata.nextLink" as request url which already contains all query params from the original request but we still pass **kwargs to the requests.request constructor, so the values in the "params" dictionary get added again to the request, causing all request query params to be duplicated.

Disruption commented 2 years ago

Pull request done on #27