Sharepoint_

Rohit Kulkarni 686 Reputation points
2022-09-13T09:07:10.813+00:00

Hello Team,

I am trying to read the file from SharePoint and upload into Azure blob storage.WHile trying upload the file into blob at that time i am getting error :

from sharepoint import *
import re
import sys,os,json
from azure.storage.blob import BlobClient
from pathlib import PurePath

folder_name = 'Evotec/Global Account Plan/Archive'
file_name = 'Gold Sheet Evotec.xlsx'
file_name_pattern = 'Gold Sheet'

Save file

file_url is the relative url of the file in sharepoint

file_path = os.path.abspath(file_name)

with open(file_name,"wb") as f:

f.download(f)

f.close()

read json file

ROOT_DIR = os.path.dirname(os.path.abspath(file))

ROOT_DIR = os.path.dirname(os.path.abspath(''))

config_path = PurePath(ROOT_DIR, 'config.json')

with open(config_path) as config_file:

config = json.load(config_file)

config = config['azure_storage']

AZURE_ACCOUNT_NAME='xyz'
AZURE_ACCESS_KEY=''
CONTAINER_NAME= 'xyz/Bronze/Salesforce'
AZURE_CONN_STR=f'DefaultEndpointsProtocol=https;AccountName={AZURE_ACCOUNT_NAME};AccountKey={AZURE_ACCESS_KEY};EndpointSuffix=core.windows.net'

functions used for azure storage

def upload_file_to_blob(file_obj, file_name):
blob = BlobClient.from_connection_string(
conn_str=AZURE_CONN_STR,
container_name=CONTAINER_NAME,
blob_name=file_name,
credential=AZURE_ACCESS_KEY
)
blob.upload_blob(file_obj)

def get_file(file_n, folder):
file_obj = SharePoint().download_file(file_n, folder)
upload_file_to_blob(file_obj, file_n)

def get_files(folder):
files_list = SharePoint().download_files(folder)
for file in files_list:
get_file(file['Name'], folder)

def get_files_by_pattern(pattern, folder):
files_list = SharePoint().download_files(folder)
for file in files_list:
if re.search(pattern, file['Name']):
get_file(file['Name'], folder)

if name == 'main':
if file_name != 'None':
get_file(file_name, folder_name)
elif file_name_pattern != 'None':
get_file_name_pattern(file, folder_name)
else:
get_files(folder_name)

I am getting error :

AttributeError: 'SharePoint' object has no attribute 'download_file'


AttributeError Traceback (most recent call last)
<command-3758021352223721> in <cell line: 58>()
if name == 'main':
if file_name != 'None':
---> get_file(file_name, folder_name)
elif file_name_pattern != 'None':
get_file_name_pattern(file, folder_name)

<command-3758021352223721> in get_file(file_n, folder)

  def get_file(file_n, folder):  

---> file_obj = SharePoint().download_file(file_n, folder)
upload_file_to_blob(file_obj, file_n)

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,162 questions
{count} votes

1 answer

Sort by: Most helpful
  1. PRADEEPCHEEKATLA-MSFT 88,716 Reputation points Microsoft Employee
    2022-09-15T10:07:40.797+00:00

    Hello @Rohit Kulkarni ,

    As I said on your previous threads:

    Unfortunately, you cannot read/write Share point files in Azure Databricks.

    Reason: Share point is not supported source in Azure Databricks.

    For more details, refer to Azure Databricks - Data sources.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.