SSL Error when connecting to a company Exchange Server

Multi tool use
SSL Error when connecting to a company Exchange Server
I try to send mails from out company exchange server via Python. My problem is, that I get a SSL error. I read a lot of pem-, cer-, crt-files, but I can not connect all these information to have success. I am sure, that if one can fix the issue in my little example script, one could fix the exchange script, too.
I read a lot about certificates and ca_bundles, but I don't know how to apply all of that to my issue.
Example-Script:
import requests
requests.get('https://mail.ourserver.loc')
Error:
C:Pythonpython.exe "PATHtoMYproject/testing.py"
Traceback (most recent call last):
File "C:Pythonlibsite-packagesurllib3contribpyopenssl.py", line 441, in wrap_socket
cnx.do_handshake()
File "C:Pythonlibsite-packagesOpenSSLSSL.py", line 1806, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "C:Pythonlibsite-packagesOpenSSLSSL.py", line 1546, in _raise_ssl_error
_raise_current_error()
File "C:Pythonlibsite-packagesOpenSSL_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
[.. a lot of text..]
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
[.. a lot of text..]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='mail.ourserver.loc', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
Exchange-Script:
from exchangelib import DELEGATE, Account, Credentials, Configuration, Message
import os
import urllib3
urllib3.disable_warnings()
creds = Credentials(username='EXGE-USR', password='secret')
config = Configuration(server='mail.ourserver.loc', credentials=creds)
account = Account(primary_smtp_address="user-name@ex-ample.com", autodiscover=False, config=config,
access_type=DELEGATE)
def send(email_receiver):
m = Message(
account=account,
subject='This is a test!',
body='Hallo',
to_recipients=[email_receiver])
m.send_and_save()
receiver = 'user-name@ex-ample.com'
send(email_receiver=receiver)
print('Finish')
Error:
C:Pythonpython.exe "PATHtoMYproject//exchange_main.py"
Traceback (most recent call last):
File "C:Pythonlibsite-packagesurllib3contribpyopenssl.py", line 441, in wrap_socket
cnx.do_handshake()
File "C:Pythonlibsite-packagesOpenSSLSSL.py", line 1806, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "C:Pythonlibsite-packagesOpenSSLSSL.py", line 1546, in _raise_ssl_error
_raise_current_error()
File "C:Pythonlibsite-packagesOpenSSL_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
[.. a lot of text..]
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:Pythonlibsite-packagesrequestsadapters.py", line 440, in send
timeout=timeout
File "C:Pythonlibsite-packagesurllib3connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:Pythonlibsite-packagesurllib3utilretry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='mail.ourserver.loc', port=443): Max retries exceeded with url: /EWS/Exchange.asmx (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
[.. a lot of text..]
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='mail.ourserver.loc', port=443): Max retries exceeded with url: /EWS/Exchange.asmx (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
Process finished with exit code 1url: /EWS/Exchange.asmx (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
[.. a lot of text..]
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='mail.ourserver.loc', port=443): Max retries exceeded with url: /EWS/Exchange.asmx (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
Process finished with exit code 1
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.