问题
I am trying a get a list items from SharePoint to Python, here is the code I am using for the poc
ctx_auth = AuthenticationContext(url='https://SharePointSiteURL')
if ctx_auth.acquire_token_for_user(username='MyUser@Company.onmicrosoft.com',password='MyPassword'):
ctx = ClientContext('https://SharePointSiteURL', ctx_auth)
lists = ctx.web.lists
ctx.load(lists)
The issue I am getting following error "Error: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /GetUserRealm.srf (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')))"
I am trying to set the ssl-verify=none to get the poc moving, Any ideas on how I can do that with AuthenticationContext
Thank you Nate
回答1:
In the latest version RequestOptions.verify
property is exposed which allows:
to control whether to verify the server's TLS certificate which accepts:
- boolean value (defaults to
True
)- string value, which represents path to a CA bundle to use
Example
Certificate verification could be disabled via underlying HTTP request object as demonstrated below:
def disable_ssl(request):
request.verify = False # Disable certification verification
ctx = ClientContext.connect_with_credentials("https://contoso.sharepoint.com",
UserCredential(username,
password)
ctx.get_pending_request().beforeExecute += disable_ssl
web = ctx.web
ctx.load(web)
ctx.execute_query()
print(web.properties["Url"])
Note
Once disabled, urllib3
might complain with InsecureRequestWarning warning which is expected given unverified HTTPS request is being made to host
{tenant}.sharepoint.com
. Adding certificate verification is strongly advised.
Installation
Since it requires the latest version, it could be installed from GitHub (until it gets published in PyPI):
pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git
来源:https://stackoverflow.com/questions/61800799/facing-issue-with-connecting-to-sharepoint-online-from-python-due-to-cert-issue