I am trying to save the image file got by requests.get()
def get_image_file(class_path,image_id):
r = requests.get(BASE_REQUEST_URL+'/image/'+image_id+'/download', stream=True)
print(r.url)
if r.status_code == 200:
with open(IMAGE_PATH+class_path+str(INCR)+'.jpg', 'wb+') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
print("Image saved")
else:
print('Can not save the image.')
So, if image is benign, image will go to 'benign' folder. When I call the function
get_image_file('benign/','5436e3acbae478396759f0d5')
Here what I get:
https://isic-archive.com/api/v1/image/5436e3acbae478396759f0d5/download
Traceback (most recent call last):
File "image_fetch.py", line 59, in <module>
get_image_file('benign/','5436e3acbae478396759f0d5')
File "image_fetch.py", line 34, in get_image_file
with open(IMAGE_PATH+class_path+str(INCR)+'.jpg', 'wb+') as f:
FileNotFoundError: [Errno 2] No such file or directory: '~/tf_files/benign/0.jpg'
I thought the problem is in the write permission.I tried to use 'wb','wb+','a+', but nothing helped.