Skip to content

Commit b7ee152

Browse files
committed
Solved Download Function Error, by correctly handling the response of download
1 parent 33aff40 commit b7ee152

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

fri/test.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import time
55

66
# function to test upload() method.
7-
87
def upload(files):
98
url = "http://127.0.0.1:5000/upload/test?apikey=xyz"
109
payload={}
@@ -61,8 +60,13 @@ def openJupyter():
6160

6261
# function to test download() method.
6362
def download(dir, subDir, fileName , apikey ):
64-
url = "http://127.0.0.1:5000/download/"+dir+"?"+"fetchDir="+subDir+"&"+"fetch="+ fileName+"&"+"apikey="+apikey
65-
urllib.request.urlretrieve(url, fileName)
63+
url = "http://127.0.0.1:5000/download/" + dir + "?" + "fetchDir=" + subDir + "&" + "fetch=" + fileName + "&" + "apikey=" + apikey
64+
response = requests.get(url)
65+
if response.status_code == 200:
66+
with open(fileName, 'wb') as f:
67+
f.write(response.content)
68+
else:
69+
print(f"Failed to download: {response.status_code}, {response.text}")
6670

6771
# file list to be uploaded
6872
cur_path = os.path.dirname(os.path.abspath(__file__))

0 commit comments

Comments
 (0)