-
-
Notifications
You must be signed in to change notification settings - Fork 370
Expand file tree
/
Copy pathset_proxy.py
More file actions
26 lines (19 loc) · 879 Bytes
/
Copy pathset_proxy.py
File metadata and controls
26 lines (19 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
Demonstrates how to configure a proxy for all SharePoint REST API requests.
Proxy is set at the transport level, ensuring it applies to ALL requests
including internal ones (form digest).
For MSAL authentication requests to login.microsoftonline.com, set the
``HTTPS_PROXY`` environment variable instead — MSAL reads it automatically.
Usage:
export HTTPS_PROXY="http://proxy:8080"
python set_proxy.py
See https://learn.microsoft.com/en-us/sharepoint/dev/apis/sharepoint-rest-api
"""
from office365.sharepoint.client_context import ClientContext
ctx = (
ClientContext("https://contoso.sharepoint.com/sites/team")
.with_client_certificate("your_tenant", "your_client_id", "your_thumbprint")
.with_transport(proxies={"http": "http://proxy:8080", "https": "http://proxy:8080"})
)
web = ctx.web.get().execute_query()
print(f"Connected to: {web.url}")