from office365.runtime.http.requests_auth import AuthenticationContext
from requests.exceptions import RequestException
username = "your_username"
password = "your_app_password"
site_url = "https://your-sharepoint-site.sharepoint.com/sites/your-site"
retry_attempts = 3 # Number of retry attempts
for attempt in range(retry_attempts):
try:
ctx_auth = AuthenticationContext(url=site_url)
if ctx_auth.acquire_token_for_user(username, password):
authcookie = ctx_auth.get_authentication_cookie()
break # Successfully obtained the authentication cookie
except RequestException as e:
print(f"Attempt {attempt + 1} failed: {str(e)}")
else:
print("Maximum retry attempts reached. Unable to obtain authentication cookie.")