From 09652b0d27bf3dd0c0bb1e0e84c0b2710339cd34 Mon Sep 17 00:00:00 2001 From: Mohamed Akram Date: Thu, 15 Oct 2020 18:36:36 +0400 Subject: [PATCH] Fix downloading zero-byte files (#301) --- pyicloud/services/drive.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pyicloud/services/drive.py b/pyicloud/services/drive.py index 83b3363..0242d75 100644 --- a/pyicloud/services/drive.py +++ b/pyicloud/services/drive.py @@ -1,10 +1,12 @@ """Drive service.""" from datetime import datetime, timedelta import json +import io import mimetypes import os import time from re import search +from requests import Response from six import PY2 @@ -260,6 +262,11 @@ class DriveNode(object): def open(self, **kwargs): """Gets the node file.""" + # iCloud returns 400 Bad Request for 0-byte files + if self.data["size"] == 0: + response = Response() + response.raw = io.BytesIO() + return response return self.connection.get_file(self.data["docwsid"], **kwargs) def upload(self, file_object, **kwargs):