你好,
我試圖複製xlx文件從sharepoint和遷移到Azure blob存儲
用戶名= app_config_client.get_configuration_setting(關鍵= BIAppConfig: SharepointUsername,標簽= BIApp) value
密碼= app_config_client.get_configuration_setting(關鍵= BIAppConfig: SharepointPassword,標簽= BIApp) value
SHAREPOINT_URL = app_config_client.get_configuration_setting(關鍵= BIAppConfig: SharepointUrl,標簽= BIApp) value
SHAREPOINT_SITE = app_config_client.get_configuration_setting(關鍵= BIAppConfig: SharepointSite,標簽= BIApp) value
SHAREPOINT_DOC = app_config_client.get_configuration_setting(關鍵= BIAppConfig: SharepointDocument,標簽= BIApp) value
SharePoint類:
def身份驗證(自我):
自我。authcookie = Office365 (SHAREPOINT_URL用戶名=用戶名、密碼=密碼).GetCookies ()
自我。站點=站點(SHAREPOINT_SITE version =版本。v365 authcookie = self.authcookie)
返回self.site
def connect_folder(自我,folder_name):
自我。auth_site = self.auth ()
自我。sharepoint_dir = "。加入([SHAREPOINT_DOC folder_name])
自我。文件夾= self.auth_site.Folder (self.sharepoint_dir)
返回self.folder
def download_file(自我、file_name folder_name):
自我。_folder = self.connect_folder (folder_name)
返回self._folder.get_file (file_name)
def _get_files_list(自我,folder_name):
自我。_folder = self.connect_folder (folder_name)
返回self._folder.files
def download_files(自我,folder_name):
自我。_files_list = self._get_files_list (folder_name)
返回self._files_list
# 1 args = SharePoint文件夾名稱。
folder_name = ' Evotec /全球賬戶計劃/歸檔的
# 2參數= SharePoint文件名。
file_name = '黃金表Evotec.xlsx '
# 3參數= SharePoint文件名模式
file_name_pattern = '黃金板'
#讀取json文件
# # ROOT_DIR = os.path.dirname (os.path.abspath (__file__))
ROOT_DIR = os.path.dirname (os.path.abspath ("))
config_path = PurePath (ROOT_DIR,“配置”)
# # config_file張開(config_path):
# #配置= json.load (config_file)
# # =配置設置(“azure_storage”)
# # # &路徑存儲賬戶
AZURE_ACCOUNT_NAME = app_config_client.get_configuration_setting(關鍵= BIAppConfig: storageAccountName,標簽= BIApp) value
AZURE_ACCESS_KEY = app_config_client.get_configuration_setting(關鍵= BIAppConfig: storageAccountAccessKey,標簽= BIApp) value
CONTAINER_NAME = app_config_client.get_configuration_setting(關鍵= BIAppConfig: salesforceContainerName,標簽= BIApp) value
AZURE_CONN_STR = f 'DefaultEndpointsProtocol = https;帳號名稱= {AZURE_ACCOUNT_NAME}; AccountKey = {AZURE_ACCESS_KEY}; EndpointSuffix =core.windows.net”
KV_CREDENTIAL = ClientSecretCredential (tenant_id = tenant_id client_id = client_id client_secret = client_secret)
KV_SECRETCLIENT = SecretClient (vault_url = KEYVAULT_URI憑據= KV_CREDENTIAL)
#用於azure存儲功能
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,
憑據= AZURE_ACCESS_KEY
)
blob.upload_blob (file_obj)
def get_file (file_n、文件夾):
file_obj = SharePoint ()。download_file (file_n文件夾)
upload_file_to_blob (file_obj file_n)
def get_files(文件夾):
files_list = SharePoint () .download_files(文件夾)
在files_list文件:
get_file(文件(“名字”),文件夾)
def get_files_by_pattern(模式、文件夾):
files_list = SharePoint () .download_files(文件夾)
在files_list文件:
如果re.search(模式、文件['名字']):
get_file(文件(“名字”),文件夾)
if __name__ = =“__main__”:
如果file_name ! = '沒有':
get_file (file_name folder_name)
elif file_name_pattern ! =“沒有”:
folder_name get_file_name_pattern(文件)
其他:
get_files (folder_name)
我得到錯誤:
AttributeError:‘SharePoint對象沒有屬性“download_file”
AttributeError回溯(最近調用最後)
<命令- 3758021352223721 > <細胞係:62 > ()
if __name__ = =“__main__”:
如果file_name ! = '沒有':
推薦- - - - - - > get_file (file_name folder_name)
elif file_name_pattern ! =“沒有”:
folder_name get_file_name_pattern(文件)
<命令- 3758021352223721 > get_file (file_n文件夾)
def get_file (file_n、文件夾):
推薦- - - - - - > file_obj = SharePoint ()。download_file (file_n文件夾)
upload_file_to_blob (file_obj file_n)
請建議阿曼。
問候
羅希特