Skip to content

issue with connecting to SharePoint Online from Python due to cert issue #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nkanne opened this issue May 16, 2020 · 0 comments
Open
Labels

Comments

@nkanne
Copy link

nkanne commented May 16, 2020

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

Vadim helped in updating the function to include flag for SSL verification. Here is the information from stackoverflow

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

Certification 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


Issue I am facing

site-packages\urllib3\connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: urllib3.readthedocs.io/en/latest/… InsecureRequestWarning, Traceback (most recent call last): File "C:\LocalUser\AppData\Roaming\Python\Python37\site-packages\office365\runtime\client_request.py", line 36, in execute_query response.raise_for_status()

File "C:\LocalUser\AppData\Roaming\Python\Python37\site-packages\requests\models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: MySharePointSiteURL/_api/Web During handling of the above exception, another exception occurred:

I have imported urllib3 and disabled warnings
import urllib3 urllib3.disable_warnings()

After urllib3.disable_warnings() , I am getting similar error File "C:,,,,Python\Python37\site-packages\requests\models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url:

It is a SharePoint Online site.
Thanks
Nate

@vgrem vgrem added the question label May 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants