knackpy icon indicating copy to clipboard operation
knackpy copied to clipboard

Sanitize file paths when downloading files

Open DeannaDS opened this issue 3 years ago • 1 comments

If you pass in a label_key field to the downloads function, and the data in that field has characters that are not allowed in a file name, it does not escape them or gracefully fail. It hard fails with an "invalid argument"

OSError Traceback (most recent call last) in 10 field="field_508", 11 out_dir="_downloads", ---> 12 label_keys=["field_499"] 13 )

~.conda\envs\ds775\lib\site-packages\knackpy\app.py in download(self, container, field, out_dir, label_keys) 501 ) 502 --> 503 download_count = self._download_files(downloads) 504 505 logger.debug(f"{download_count} files downloaded.")

~.conda\envs\ds775\lib\site-packages\knackpy\app.py in _download_files(self, downloads) 458 res.raise_for_status() 459 --> 460 with open(filename, "wb") as fout: 461 fout.write(res.content) 462 count += 1

OSError: [Errno 22] Invalid argument: '_downloads\Youth Define "Constructive" Activity_definitionofconstructive2ndgroup.jpg'

DeannaDS avatar Dec 22 '21 16:12 DeannaDS