Not able to upload file to sharepoint using python office365-REST-Python-Client python package

499 Views Asked by At

I have files in one in one of the path and wants to upload that into sharepoint folder but getting below error with multiple "another exception occurred".

Traceback (most recent call last):

File "/path/Python/3.7/lib/python/site-packages/urllib3/util/connection.py", line 73, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 748, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/path/Python/3.7/lib/python/site-packages/urllib3/connection.py", line 182, in _new_conn self, "Failed to establish a new connection: %s" % e urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f8a3081ca90>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/path/Python/3.7/lib/python/site-packages/urllib3/util/retry.py", line 574, 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: /GetUserRealm.srf (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f8a3081ca90>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "path/Python/3.7/lib/python/site-packages/requests/adapters.py", line 519, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /GetUserRealm.srf (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f8a3081ca90>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "path/Python/3.7/lib/python/site-packages/office365/runtime/auth/providers/saml_token_provider.py", line 102, in get_authentication_cookie logger.error(e.response.text) AttributeError: 'NoneType' object has no attribute 'text'

above error i'm getting while running below code till ctx.execute_query()

from office365.runtime.auth.client_credential import ClientCredential
from office365.runtime.client_request_exception import ClientRequestException
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
import io
import datetime
import pandas as pd

username = 'username'
password = 'password'
sp_site = 'link'
relative_url = "/sites/mysite/Shared%20Documents/General"
client_credentials = UserCredential(username, password)
ctx = ClientContext(sp_site).with_credentials(client_credentials)
libraryRoot = ctx.web.get_folder_by_server_relative_path(relative_url)
ctx.load(libraryRoot)
ctx.execute_query() ## code is failing here only

#if you want to get the folders within <sub_folder> 
folders = libraryRoot.folders
ctx.load(folders)
ctx.execute_query()
for myfolder in folders:
    print("Folder name: {0}".format(myfolder.properties["ServerRelativeUrl"]))
0

There are 0 best solutions below