1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] session.get not getting corrected file on remote server/local server

Discussão em 'Python' iniciado por Stack, Setembro 13, 2025.

  1. Stack

    Stack Membro Participativo

    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))

    Continue reading...

Compartilhe esta Página