英文:
How to pass parameters like auth ,headers, verify ,stream when using downloader object of pypdl module to download data from url parallely
问题
from pypdl import Downloader
dl = Downloader()
dl.start(url, filepath)
由于我无法提供身份验证和头部详细信息,无法连接到源,因此会出现连接错误。
英文:
from pypdl import Downloader
dl = Downloader()
dl. start(url , filepath)
Here since I am not able to give the auth ,headers details. I am unable to connect with the source and it gives the connection error
答案1
得分: 2
我是pypdl的维护者,它以前没有任何选项来添加标头,但现在我已经添加了该选项(pypdl 0.0.8)。现在,您可以通过设置Downloader
的header
(字典)属性来设置自定义标头。
from pypdl import Downloader
def main():
# 创建一个新的下载器对象
dl = Downloader()
# 使用自定义标头设置用户代理
dl.headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"}
# 启动下载
dl.start(
url='https://speed.hetzner.de/100MB.bin',
filepath='100MB.bin')
if __name__ == '__main__':
main()
如果您正在使用多线程下载,请确保不设置任何range header
。
英文:
I am the maintainer of pypdl, it didn't have any option to add header but now i have added that option (pypdl 0.0.8). now you can set custom headers via setting the header
(dict) attribute of Downloader
from pypdl import Downloader
def main():
# create a new downloader object
dl = Downloader()
# Use custom headers to set user-agent
dl.headers = {User-Agent:"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"}
# start the download
dl.start(
url='https://speed.hetzner.de/100MB.bin',
filepath='100MB.bin')
if __name__ == '__main__':
main()
make sure to not set any range header
if you are using multithread downloading
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论