[英]Download .img file from given link using wget-module
I am trying to download a file in python using the wget module .我正在尝试使用wget 模块在 python 中下载文件。 The problem is, that the original file size is about 125mb, the file size of my download is just ~7kb
问题是,原始文件大小约为 125mb,我下载的文件大小仅为 ~7kb
My code:我的代码:
import wget
download_link = "https://dl.twrp.me/gauguin/twrp-3.5.2_10-0-gauguin.img"
wget.download(download_link)
Output:输出:
100% [................................................................................] 6846 / 6846'twrp-3.5.2_10-0-gauguin.img'
File size:文件大小:
francesco@francesco-ubuntu:~/Dokumente/GIT/python_adb$ ls -al twrp-3.5.2_10-0-gauguin.img
-rw-rw-r-- 1 francesco francesco 6846 Feb 6 22:26 twrp-3.5.2_10-0-gauguin.img
Am I doing something wrong?难道我做错了什么? Like I said, the original file size is ca 125mb, the file I downloaded around 7kb
就像我说的,原始文件大小是 ca 125mb,我下载的文件大约 7kb
Thanks in advance!提前致谢!
To correctly download the file, try to set Referer<\/code> and
User-Agent<\/code> HTTP header (example with
requests<\/code> module):
要正确下载文件,请尝试设置
Referer<\/code>和
User-Agent<\/code> HTTP 标头(以
requests<\/code>模块为例):
import requests
url = "https://dl.twrp.me/gauguin/twrp-3.5.2_10-0-gauguin.img"
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0",
"Referer": "https://dl.twrp.me/gauguin/twrp-3.5.2_10-0-gauguin.img",
}
r = requests.get(url, headers=headers)
with open("twrp-3.5.2_10-0-gauguin.img", "wb") as f_out:
f_out.write(r.content)
So i found the solution but using request<\/code> library, but I think you will be able to fix your code.
所以我找到了解决方案,但使用了
request<\/code>库,但我认为你将能够修复你的代码。
The fix is easy, you just need to specify
Referer<\/code> header
修复很简单,你只需要指定
Referer<\/code>头
Referer: https://dl.twrp.me/gauguin/twrp-3.5.2_10-0-gauguin.img
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.