Script to download files into an attachment field is typing the files incorrectly

Cross-posted, but updated

I’m using the popular script for downloading attachments from a url to an attachment field, but I’m running into issues. The url I’m using is a direct download link to an mp3 file in Box, and this script is working properly half the time, but in some cases rather than downloading the mp3 file, it’s scraping the html of the download page instead and loading it into AT as (what looks like) a text file with an mp3 extension.

I’ve opened the file preview for one of the incorrectly downloaded files in Box and it looks like it’s asking for Box credentials, but I’ve double-checked the urls in Box pre-download and they’re all set to be downloadable with just access to the link, so it isn’t (or shouldn’t be) a permissions issue. I’ve been able to open them even when not logged in to Box. When I download one of the files it is unsurprisingly corrupt.

Has anybody run into this before?