0
good afternoon. How can I download a file from a site in the URL by setting the header? For example, I have a file on a site and I want to download in python, just returns me a 403 error, so how do I manage to set the header I will use? I believe that will not give error 403.
import requests
url = "http://example.com/uploads/archive.ts"
headerr = {'Host': 'example.com',
'User-agent': 'Windows 10',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-language': 'en-US,en; q=0.5',
'Accept-encoding': 'gzip, deflate',
'Connection': 'close'}
#tenho que fazer o download do arquivo usando o cabeçalho acima. Como faço?
try:
requisicao = requests.get(url, headers=headerr)
print("Feito.")
except Exception as e:
print("Erro", e)
So... Actually it is like this, when opening the site with the file in my browser, for being a file . ts, it downloads instantly. But when sending the request by setting the header, instead of downloading the file, it just shows its contents. If I do not set anything in the header, it returns me a 403. The plan was for me to make a request setting the header and be able to download, you know? Thanks for the help.
– João silva
Maybe the authentication is via cookie and your browser is already authenticated, so you can perform the request smoothly.
– Damião Martins