knackpy
knackpy copied to clipboard
Sanitize file paths when downloading files
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)
~.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'