Slow Uploads using Google Drive API with Python
@sqrrrl 已經在處理了。
開始於 2024年11月7日。
評估
這個 Issue 還沒有評估資料。
描述
Expected Behavior
Automatically upload large files daily to Google Drive using Python, with upload speeds matching my internet connection.
Actual Behavior
The upload speed is stuck at around 20 Mbps, even when I use a faster network or adjust the chunk size in the script. I initially thought the issue was a limit within the Python code, but after testing the network speed in the same script, it showed speeds over 100 Mbps.
Here is my script:
file_name = os.path.basename(file_path)
file_size = os.path.getsize(file_path) / (1024 * 1024)
media = MediaFileUpload(file_path, mimetype='application/octet-stream', chunksize=256*1024 * 1024, resumable=True)
file_metadata = {
'name': file_name,
'parents': [folder_id] if folder_id else []
}
try:
request = service.files().create(media_body=media, body=file_metadata)
start_time = time.time()
response = request.execute()
print(f"Uploaded '{file_name}' successfully at {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
elapsed_time = time.time() - start_time
upload_speed = file_size / elapsed_time
print(f"Time used: {elapsed_time}\nUpload speed: {upload_speed:.2f} MB/s or {upload_speed*8:.2f} Mbps")
return True
except HttpError as error:
print(f"Failed to upload '{file_name}': {error}")
return False
I also tried changing the response part to:
response = None
while response is None:
status, response = request.next_chunk()
if status:
print("Uploaded %d%%." % int(status.progress() * 100))
but it showed almost the same results.
Specifications
- Python version: 3.12.7
- OS: Windows
- 主要語言
- Python
- 星號
- 1.4k
- 分支
- 917
- 平均合併
- 3 分鐘
- 30 天內合併 PR
- 1
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
googleworkspace/python-samples 的其他 Issue
-
ايقاف البحث الأمن可能重新可做 @sqrrrl 於 400 天前認領,目前沒有進行中的 PR。 未關閉
googleworkspace/python-samples#2434 · 已指派 1 人 ·
-
403 error from google after a few successful runs of my code可能重新可做 @vinay-google 於 912 天前認領,目前沒有進行中的 PR。 未關閉
googleworkspace/python-samples#1424 · 已指派 1 人 ·
-
How to see the progress of files which is getting uploaded可能重新可做 @vinay-google 於 928 天前認領,目前沒有進行中的 PR。 未關閉
googleworkspace/python-samples#1404 · 已指派 1 人 ·
-
Phyton Samples可能重新可做 @PierrickVoulet 於 975 天前認領,目前沒有進行中的 PR。 未關閉
googleworkspace/python-samples#1279 · 已指派 1 人 ·
-
DefaultCredentialsError: Your default credentials were not found. To set up Application Default Credentials可能重新可做 @sqrrrl 於 1018 天前認領,目前沒有進行中的 PR。 未關閉
googleworkspace/python-samples#1278 · 1 則留言 · 已指派 1 人 ·
查看 googleworkspace/python-samples 的全部 Issue
相似的 Issue
-
area: ci bug good first issue help wanted
難度 2/5 1-3 小時 新手友好度 84/100
hffgzktbcc-blip/ounce-core#484 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 66/100
ranxianglei/billion-context#7063 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
-
needs-triage
難度 2/5 1-3 小時 新手友好度 84/100
MakazhanAlpamys/Soup#2971 ·
維護者通常 1 天內回覆