0

Issues connecting to sharepoint 2019 with the code below. How do I disable ssl? When i try the same code with sharepoint online, everything works fine but not sharepoint 2019. Any help will be really appreciated. Issues connecting to sharepoint 2019 with the code below. How do I disable ssl? When i try the same code with sharepoint online, everything works fine but not sharepoint 2019. Any help will be really appreciated.

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
import os
import requests

def disable_ssl(request):
    request.verify = False

app_settings = {
    'url': 'https://mysp.com/sites/'+'sitenameGG'+'/',
    'client_id': 'xxxx',
    'client_secret': 'xxxx',
}
context_auth = AuthenticationContext(app_settings['url'])
context_auth.acquire_token_for_app(client_id=app_settings['client_id'], client_secret=app_settings['client_secret'])



ctx = ClientContext(app_settings['url'], context_auth)
web = ctx.web
ctx.load(web)
ctx.pending_request().beforeExecute += disable_ssl
ctx.execute_query()


response = File.open_binary(ctx, "/sites/sitenameGG/"+('some%20test%20lib/hello.csv'))
with open(r'C:\Users\somepath\'+filename, 'wb') as local_file:
    local_file.write(response.content)

Error Results/Traceback of below:

Traceback (most recent call last):
  File "C:\Python310\lib\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Python310\lib\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "C:\Python310\lib\urllib3\connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "C:\Python310\lib\urllib3\connection.py", line 414, in connect
    self.sock = ssl_wrap_socket(
  File "C:\Python310\lib\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "C:\Python310\lib\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Python310\lib\ssl.py", line 512, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Python310\lib\ssl.py", line 1070, in _create
    self.do_handshake()
  File "C:\Python310\lib\ssl.py", line 1341, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python310\lib\requests\adapters.py", line 440, in send
    resp = conn.urlopen(
  File "C:\Python310\lib\urllib3\connectionpool.py", line 786, in urlopen
    retries = retries.increment(
  File "C:\Python310\lib\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='mysp.somesiteGG.com', port=443): Max retries exceeded with url: /sites/somesiteGG/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python310\lib\office365\runtime\auth\providers\acs_token_provider.py", line 41, in get_app_only_access_token
    realm = self._get_realm_from_target_url()
  File "C:\Python310\lib\office365\runtime\auth\providers\acs_token_provider.py", line 70, in _get_realm_from_target_url
    response = requests.head(url=self.url, headers={'Authorization': 'Bearer'})
  File "C:\Python310\lib\requests\api.py", line 102, in head
    return request('head', url, **kwargs)
  File "C:\Python310\lib\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python310\lib\requests\sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python310\lib\requests\sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python310\lib\requests\adapters.py", line 518, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='mysp.somesiteGG.com', port=443): Max retries exceeded with url: /sites/somesiteGG/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\G14826\PycharmProjects\pythonProject\access_rest.py", line 22, in <module>
    context_auth.acquire_token_for_app(client_id=app_settings['client_id'], client_secret=app_settings['client_secret'])
  File "C:\Python310\lib\office365\runtime\auth\authentication_context.py", line 82, in acquire_token_for_app
    return self._provider.ensure_app_only_access_token()
  File "C:\Python310\lib\office365\runtime\auth\providers\acs_token_provider.py", line 36, in ensure_app_only_access_token
    self._cached_token = self.get_app_only_access_token()
  File "C:\Python310\lib\office365\runtime\auth\providers\acs_token_provider.py", line 45, in get_app_only_access_token
    self.error = e.response.text
AttributeError: 'NoneType' object has no attribute 'text'

Process finished with exit code 1
Dixxyyy
  • 3
  • 4
  • Does your 2019 server have a valid SSL certificate? From the error message, it looks like it does not.. meaning, if you open it in a browser, do you get a security warning? – Nikolay Jun 02 '22 at 08:39
  • @Nikolay Yes it does have a valid cert and I dont get that warning when I open in browser – Dixxyyy Jun 02 '22 at 13:31
  • May be helpful: https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error Looks like your python does not see or accept the certificate of your 2019 server. There is environment variable mentioned to disable SSL check for python, PYTHONHTTPSVERIFY=0 – Nikolay Jun 02 '22 at 20:16

0 Answers0