0
因此,我想使用urllib下載二進制文件(使用gpg加密)。現在,如果我想管它:使用urllib下載二進制加密文件,將其保存爲流
this_script.py > file1
我應該能夠解密二進制文件1,但是,在GPG只是給出了一個錯誤。我不想用python保存文件,因爲我需要它來解密下載文件的程序。另外我不能使用urlretireve,因爲我不能欺騙useragent字符串,這會導致網站給我403禁止錯誤。
import urllib
url = <link_to_any_binary_file>
req = urllib.request.Request(
url,
data=None,
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0'
}
)
file_response = urllib.request.urlopen(req)
binary_file = file_response.read()
print(binary_file)