【发布时间】:2022-08-18 18:39:51
【问题描述】:
我在 SharePoint Online 上使用 Microsoft SharePoint REST API 并尝试上传 pandas DataFrame as csv。如果我将DataFrame 写入本地 csv 文件并开始上传,这可以正常工作(也适用于大文件)。
现在我尝试直接从内存上传DataFrame,但对于大于 200 MB 的文件会出现错误:
output = io.BytesIO()
writer = csv.writer(output)
df.to_csv(output, **kwargs)
guid = str(uuid.uuid4()) # unique ID for identifying current upload
file_full_path = r\"/sites/\" + self._site_name + \"/\" + lib_name + \"/\" + folder_path + \"/\" + file_name
offset = 0
file_size = output.__sizeof__()
next_buffer = True
url = self._URL + \"/_api/web/GetFolderByServerRelativeUrl(\'\" + lib_name + \"/\" + folder_path + \"\')/Files/add(url = \'\" + file_name + \"\')\"
response = requests.request(\"POST\", url, headers=headers, proxies=self._proxies)
#init uploading
url = self._URL + \"/_api/web/GetFileByServerRelativePath(DecodedUrl=\'\" + file_full_path + \"\')/StartUpload(uploadId=guid\'\" + guid + \"\')\"
response = requests.request(\"POST\", url, headers=headers, proxies=self._proxies)
#read file and upload it in a bytestream according to the given chunk size
while next_buffer:
actual_offset = offset
offset += chunksize
# continue uploading in chunks as long as the upcoming chunk is smaller than the actual file.
# otherwise finish uploading by decreasing the chunk size to the number of bytes left.
if offset >= file_size:
chunksize = file_size - (offset - chunksize)
next_buffer = False
url = self._URL + \"/_api/web/GetFileByServerRelativePath(DecodedUrl=\'\" + file_full_path + \"\')/FinishUpload(uploadId=guid\'\" + guid + f\"\',fileOffset={actual_offset})\"
else:
url = self._URL + \"/_api/web/GetFileByServerRelativePath(DecodedUrl=\'\" + file_full_path + \"\')/ContinueUpload(uploadId=guid\'\" + guid + f\"\',fileOffset={actual_offset})\"
# read current chunk and add it to the request
output.seek(actual_offset)
buffer = output.read(chunksize)
response = requests.request(\"POST\", url, headers=headers, data = buffer, proxies=self._proxies)
这是错误消息:
error\":{\"code:\"-2130575135, Microsoft.SharePoint.Utilities.SPBITSSessionIncompleteException
我不明白为什么我会收到此错误。
-
请修剪您的代码,以便更容易找到您的问题。请按照以下指南创建minimal reproducible example。
标签: python pandas sharepoint