
11,701 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am trying to connect to Sharepoint and get all PDF files in the Sharepoint directory
cert_thumbprint = "43EA...2910F3D106F0954478"
private_key = """-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDO5sFhHefRsI+m
O6tBWs0OnNRr44RH1ljbjByK2KQvbKI+KFgwyeyogt3065lY6W4Xpw3IxqZZiSmE
...
KerXXf8mIadaCe3rLmQGernc6O4ZP+sbRrw6zGFsw/zd2Zmuzov62DbAAQKBgQCs
...
c/dppy+PQQYQ/29WMt5/ITTI0lEHRqkZdNBLJcWX6iJ2Lh+QcTBeIzv0RzxCfZCl
bmRwnYv0Rp2CILKY28sn54ivMxMEorSaO0NhlOM5NCQUuYNwt2+JiIdjccmrNJs0
O8wT9fwTf9V1xV6m7pQ9EHv4DA==
-----END PRIVATE KEY-----"""
cert = {
"private_key": private_key,
"thumbprint": cert_thumbprint
}
import msal
import requests
app = msal.ConfidentialClientApplication(
"1257aa45-...-...-...-56fae68aebfe",
authority=f"https://login.microsoftonline.com/91b358ee-...-...-...-0a2b9d5940b8",
client_credential=cert
)
token_response = app.acquire_token_for_client(
scopes=["https://mygmbh.sharepoint.com/.default"])
access_token = token_response.get('access_token')
headers = {
'Authorization': 'Bearer ' + access_token,
'Accept': 'application/json;odata=verbose',
'Content-Type': 'application/json'
}
sharepoint_url = "https://mygmbh.sharepoint.com/sites/QMS/_api/web/GetFolderByServerRelativeUrl('Freigegebene Dokumente')/Files"
response = requests.get(url=sharepoint_url, headers=headers)
files = response.json()['d']['results']
pdf_files = [file for file in files if file['Name'].endswith('.pdf')]
Until this step, I can see the list of PDF files
But for the below, I got an error
for file in pdf_files:
download_url = file['ServerRelativeUrl']
token_response2 = app.acquire_token_for_client(
scopes=["https://mygmbh.sharepoint.com/.default"])
access_token2 = token_response2.get('access_token')
headers2 = {
'Authorization': 'Bearer ' + access_token2,
'Accept': 'application/json;odata=verbose',
'Content-Type': 'application/json'
}
dl = "https://mygmbh.sharepoint.com" + download_url
response2 = requests.get(dl, headers=headers2, stream=True) # <--- ERROR
If you want to know my permissions
Can anyone help me with this? I want to be able to download PDF files without permission issues.