SharePoint authentication with python

Bo 0 Reputation points
2023-06-28T01:36:26.86+00:00

Hi,

I am trying to use Python sharepy library to connect to the sharepoint of our company as follows, with the url provided by the company. However, it returned with the following error,

requests.exceptions.SSLError: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /GetUserRealm.srf?login='my login name'&xml=1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1002)')))

Can someone please help with this? Thanks

import sharepy
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Khaled Elsayed Mohamed 1,330 Reputation points
    2023-07-06T09:34:40.2266667+00:00

    Hi Bo

    The error you're encountering with the sharepy library is related to SSL certificate verification. It indicates that the certificate presented by the server couldn't be verified. To resolve this issue, you can try the following steps:

    1. Verify your internet connectivity: Ensure that you have a stable internet connection. Check if you can access other websites or services without any SSL certificate verification issues.
    2. Update the certifi package: The certifi package contains a set of trusted CA certificates. Upgrading it to the latest version may help resolve SSL certificate verification errors. You can update it by running the following command in your Python environment:
         pip install --upgrade certifi
      
    3. Disable SSL verification (not recommended for production): As a temporary workaround, you can disable SSL certificate verification for testing purposes. However, this is not recommended for production environments as it bypasses security checks. Use the following code before making the SharePoint connection:
         import ssl
         ssl._create_default_https_context = ssl._create_unverified_context
      
      Adding these lines will override the default SSL verification behavior and allow connections to proceed without certificate verification. However, remember to use this solution judiciously and reinstate SSL verification once the underlying issue is resolved.
    4. Verify the validity of the server's certificate: If the issue persists, it's possible that the server's SSL certificate is not properly configured or is self-signed. In such cases, you may need to consult with your company's IT department or SharePoint administrator to ensure that the server's certificate is valid and properly installed.

    If none of the above solutions resolve the SSL certificate verification error, you might consider using alternative libraries like requests, urllib, or http.client to establish the connection to SharePoint. These libraries also provide options to manage SSL certificate verification or ignore it if required.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.
    0 comments No comments

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.