SSLError: CERTIFICATE_VERIFY_FAILED 1007 on Ubuntu with Python and O365 Library

Natalia Woropay-Hordziejewicz 0 Reputation points
2025-03-20T12:33:46.8133333+00:00

I am using Ubuntu and Python 3.10 to authenticate using the O365 library. When attempting to download a file from SharePoint, I encounter the following SSL error:

SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: authority and subject key identifier mismatch (_ssl.c:1007)')

Relevant Code Snippet:

from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
from O365 import Account, MSGraphProtocol, FileSystemTokenBackend
import certifi
# Set up the Key Vault name and URI
# Use DefaultAzureCredential for authentication
# Retrieve Client ID and Client Secret from Key Vault
# Set up the O365 credentials using the values retrieved from Key Vault
azure_app_credentials = (client_id, client_secret)
# Set up the protocol and token backend
protocol = MSGraphProtocol(api_version='v1.0')
token = FileSystemTokenBackend(token_path='token', token_filename='o365_token.txt')
scopes = [
    'Calendars.Read',
    'Calendars.ReadWrite',
    'Chat.Read',
    'Chat.ReadWrite',
    'Contacts.Read',
    'Contacts.Read.Shared',
    'Contacts.ReadWrite',
    'Contacts.ReadWrite.Shared',
    'email',
    'Files.Read',
    'Files.Read.All',
    'Files.ReadWrite',
    'Files.ReadWrite.All',
    'Mail.Read',
    'Mail.Read.Shared',
    'Mail.ReadBasic.Shared',
    'Mail.ReadWrite',
    'Mail.ReadWrite.Shared',
    'Mail.Send',
    'Mail.Send.Shared',
    'MailboxSettings.Read',
    'MailboxSettings.ReadWrite',
    'offline_access',
    'openid',
    'profile',
    'Sites.Read.All',
    'Sites.ReadWrite.All',
    'User.Read'
]
# Authenticate with O365
account = Account(credentials=azure_app_credentials,
                  protocol=protocol,
                  token_backend=token,
                  scopes=scopes,
                  verify_ssl=True,
                  verify_ssl_cert=certifi.where())
if not account.is_authenticated:
    account.authenticate(requested_scopes=scopes)

Thank you for help!

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,498 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.