I have a generated url that will need to open up the browser to download the file from the server. I am trying to simulate this download using Python requests library

import requests

url = r'https://www.filedownloadserver.com?docId=7700915281958&projectNumber=aaa' 
resp = requests.get(url, verify=False)
    with open('test.pdf', 'wb') as file:

the output pdf file is incorrect, from the resp.content, it returns javascript that looks like this

//<script>location.href=('https://login.fileserver.com/login1/?redirect='+encodeURIComponent(location.href));</script> location.href=('https://login.fileserver.com/login1/?redirect='+encodeURIComponent(location.href));

is there anyway I can get the actual file from the above content?

  • It is apparent from the response content that you are required to authenticate before you are allowed to download the file.
    – blhsing
    4 mins ago


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.