The process of building custom applications and tools that interact with Microsoft SharePoint, including SharePoint Online in Microsoft 365.
Thanks for the additional information.
One thing that stands out from the screenshot is that the SharePoint permissions shown are Delegated permissions (AllSites.Read and AllSites.FullControl). Since you're using with_client_certificate(...), you're using the app-only / client credential flow, which requires Application permissions rather than Delegated permissions. Microsoft's App-Only guidance also describes using SharePoint application permissions for certificate-based authentication.
In your Entra app registration, it should look something like this: