Session.get works locally but not on server/local server

I have this piece of code that works complete fine on a single python script. When I try to test it out on local server it returns a html page saying link is not vaild. (I am expecting a PDF downloaded). Both localserver and python script returns a 200. url is the download link of a pdf file on the website.

def get_file(url):
    headers = {
        'User-Agent': user_agent,
        'Cookie': cookie,
    }
    session = requests.Session()
    try:
        response = session.get(url, headers=headers, verify=False)
        filename = response.headers['Content-Disposition'].split('"')[-2]
        with open(filename, 'wb') as f:
            f.write(response.content)
        fileFullPath = os.path.abspath(filename)
        print(fileFullPath)
    except requests.exceptions.HTTPError as err:
        print("file download fail err {}".format(err.response.status_code))
Вернуться на верх