Uncategorized

rest – Can’t download file from direct link with python requests


I was trying to download a file from a direct link. When I try the link in my browser and Postman the file is successfully downloaded.

When I tried it with python requests I received a 302 status code even with requests.get(… allow_redirects=False). When I check resp.headers[“location”] it returns a different link. Here is what I did. I hid the real link for privacy reasons.

...

url = "https://store10.gofile.io/download/******************/test.txt"

resp = requests.get(url, allow_redirects=False)
print(resp.headers['location']==url) Prints "False"

with open(out, 'wb') as f:
    for chunk in resp.iter_content(chunk_size=1024):
        if chunk:
            f.write(chunk)



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *