0

I am working on a POC where I have to load data from GCS Bucket to a sharePoint Location. I am using the below code but not able to get desired result.


# Import the storage library
from google.cloud import storage
client = storage.Client()
bucket_name = 'my-bucket'
file_name = 'my-file.csv'

# Download the file from GCS
bucket = client.bucket(bucket_name)
blob = bucket.blob(file_name)
blob.download_to_filename(file_name)

# Import the office365-rest-python-client library
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File

# Set the SharePoint site URL
site_url = 'https://7rhjkshshgvavvd.sharepoint.com/sites/MyDemo/testing/'

# Authenticate with SharePoint
context = AuthenticationContext(url=site_url)
if context.acquire_token_for_user(username="XXXXXX", password="XXXXXX"):
    print("Authenticated with SharePoint")
else:
    print("Failed to authenticate with SharePoint")

# Construct a ClientContext object
client_context = ClientContext(site_url, context)

# Set the path to the file you want to upload
# Upload the file to SharePoint
file_creation_info = File.from_local_file(client_context)
sp_file = file_creation_info.upload()
client_context.execute_query()

print(f'File uploaded to SharePoint: {sp_file.server_relative_url}')

Sandeep Mohanty
  • 1,419
  • 5
  • 13
  • what exactly is the error you are having? – CaptainNabla Dec 22 '22 at 18:53
  • @CaptainNabla raise Exception('Error authenticating against Office 365. Error from Office 365:', message[0].text) Exception: ('Error authenticating against Office 365. Error from Office 365:', 'AADSTS53003: Access has been blocked by Conditional Access policies. The access policy does not allow token issuance.') – Sandeep Mohanty Dec 22 '22 at 19:30
  • Have you looked specifically for this error? There seems to be a bunch of stackoverflow entries already (e.g., [here](https://stackoverflow.com/questions/66399770/access-sharepoint-via-python), or [here](https://stackoverflow.com/questions/70730965/office-365-access-has-been-blocked-by-conditional-access-policies-the-access-po), or [here](https://stackoverflow.com/questions/55922791/azure-sharepoint-multi-factor-authentication-with-python)) – CaptainNabla Dec 23 '22 at 07:20
  • yes, but none of them are working – Sandeep Mohanty Dec 23 '22 at 07:47

0 Answers0