jasonrollins / shareplum

Pythonic SharePoint
MIT License
178 stars 96 forks source link

SSL issue - Office365 - Sharepoint Online #120

Open karthik-tableau opened 3 years ago

karthik-tableau commented 3 years ago

I'm trying to connect Sharepoint Online 2016 from Python to Insert/Update data into a list.

My Code is:

from shareplum import Site from shareplum import Office365

authcookie = Office365('https://xxxxxxx.sharepoint.com', username='karthikeyan.m@xxxxxxxxxx.com', password='xxxxxxxxx').GetCookies() site = Site('https://xxxxxxxxxx.sharepoint.com/sites/mission/', authcookie=authcookie, verify_ssl= False) sp_list = site.List('Mission Template') data = sp_list.GetListItems('All Items', rowlimit=200)

I'm getting the below error, although i passed verify_ssl = False, why?

C:\Python\python.exe "C:/PyCharm/Mission Critical.py" Traceback (most recent call last): File "C:\Python\lib\site-packages\urllib3\contrib\pyopenssl.py", line 456, in wrap_socket cnx.do_handshake() File "C:\Python\lib\site-packages\OpenSSL\SSL.py", line 1934, in do_handshake self._raise_ssl_error(self._ssl, result) File "C:\Python\lib\site-packages\OpenSSL\SSL.py", line 1671, in _raise_ssl_error _raise_current_error() File "C:\Python\lib\site-packages\OpenSSL_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): File "C:\Python\lib\site-packages\urllib3\connectionpool.py", line 597, in urlopen httplib_response = self._make_request(conn, method, url, File "C:\Python\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request self._validate_conn(conn) File "C:\Python\lib\site-packages\urllib3\connectionpool.py", line 839, in _validate_conn conn.connect() File "C:\Python\lib\site-packages\urllib3\connection.py", line 337, in connect self.sock = ssl_wrapsocket( File "C:\Python\lib\site-packages\urllib3\util\ssl.py", line 345, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "C:\Python\lib\site-packages\urllib3\contrib\pyopenssl.py", line 462, in wrap_socket raise ssl.SSLError('bad handshake: %r' % e) 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:\Python\lib\site-packages\requests\adapters.py", line 439, in send resp = conn.urlopen( File "C:\Python\lib\site-packages\urllib3\connectionpool.py", line 637, in urlopen retries = retries.increment(method, url, error=e, _pool=self, File "C:\Python\lib\site-packages\urllib3\util\retry.py", line 399, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /extSTS.srf (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): File "C:\Python\lib\site-packages\shareplum\request_helper.py", line 16, in post response = session.post(url, kwargs) File "C:\Python\lib\site-packages\requests\api.py", line 116, in post return request('post', url, data=data, json=json, kwargs) File "C:\Python\lib\site-packages\requests\api.py", line 60, in request return session.request(method=method, url=url, kwargs) File "C:\Python\lib\site-packages\requests\sessions.py", line 533, in request resp = self.send(prep, send_kwargs) File "C:\Python\lib\site-packages\requests\sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "C:\Python\lib\site-packages\requests\adapters.py", line 514, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /extSTS.srf (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): File "C:/PyCharm/Mission Critical.py", line 4, in authcookie = Office365('https://xxxxxxxxx.sharepoint.com', username='karthikeyan.m@xxxxxx.com', password='xxxxxxxx').GetCookies() File "C:\Python\lib\site-packages\shareplum\office365.py", line 88, in get_cookies sectoken = self.get_security_token(self.username, self.password) File "C:\Python\lib\site-packages\shareplum\office365.py", line 66, in get_security_token response = post(requests, url, data=body) File "C:\Python\lib\site-packages\shareplum\request_helper.py", line 20, in post raise ShareplumRequestError("Shareplum HTTP Post Failed", err) shareplum.errors.ShareplumRequestError: Shareplum HTTP Post Failed : HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /extSTS.srf (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))

Process finished with exit code 1

karthik-tableau commented 3 years ago

any inputs?

Tmagga commented 3 years ago

This is working for me: authcookie = Office365("https://XXXXXXXXX.sharepoint.com", username='my_username',password='my_password').GetCookies() site = Site("https://xxxxxxxx.sharepoint.com/sites/XXXXXX",version=Version.v365, authcookie=authcookie)

i had som issues as well until i passed the 'version='

jasonrollins commented 3 years ago

Authentication is working for some and not others. I'm not sure how to help with debugging this issue. Let me know if you determine the cause.

davidschenz commented 3 years ago

Hello - I ran into this issue and was able to resolve it by upgrade requests from 2.23.0 to 2.24.0 and urllib3 from 1.22 to 1.25.10.

jasonrollins commented 3 years ago

Thanks for the feedback. Hopefully this helps others.

travisturenne commented 3 years ago

Found a workaround to this without actually solving the SSL issues or authentication at all.

In File Explorer you can reverse the slashes of your Sharepoint site so 'https://mysharepoint.bus.com/sites/mysite' becomes '\mysharepoint.bus.com\site\mysite' You can map this like a local network drive (as long as you’re on OneDrive) and write to it the same way as if it were a conventional path. This bypasses the authentication methods. Now just use file.write() method or whatever you normally use to write files.