Skip to content

Options to follow best practices for rate limits #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wwwslinger opened this issue Apr 17, 2021 · 1 comment
Open

Options to follow best practices for rate limits #341

wwwslinger opened this issue Apr 17, 2021 · 1 comment

Comments

@wwwslinger
Copy link

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.

@vgrem
Copy link
Owner

vgrem commented Apr 20, 2021

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):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants