Office365-REST-Python-Client
Office365-REST-Python-Client copied to clipboard
Options to follow best practices for rate limits
It would be great to be able to specify a config with AppID and AppTitle, along with User Agent and the other things recommended here for avoiding the SharePoint Online obtuse rate limits.
Likewise, would love a method to pull out the "Retry-After" header and leverage it for high-hitting processes.
Happy to attempt a PR if you can point in the right direction first.
Greetings!
Sounds like a good idea to handle throttling requests, thank you for pointing out and you are more then welcome to contribute! :)
In terms of right direction here is an sample which demonstrates how to add our user agent information
Adapted from this example:
ctx = ClientContext(site_url).with_credentials(ClientCredential(client_id, client_secret))
def _construct_custom_request(request):
"""
:type request: office365.runtime.http.request_options.RequestOptions
"""
request.ensure_header("User-Agent", "NONISV|Contoso|GovernanceCheck/1.0")
# Modify default request before it gets submitted to the server
ctx.pending_request().beforeExecute += _construct_custom_request
target_web = ctx.web.get().execute_query()
Another starting point for implementing ExecuteQueryWithIncrementalRetry could be the implementation of ClientRuntimeContext.execute_query_retry method
def execute_query_retry(self, max_retry=5, timeout_secs=5, success_callback=None, failure_callback=None):