How to pass parameters like auth ,headers, verify ,stream when using downloader object of pypdl module to download data from url parallely

huangapple go评论62阅读模式
英文:

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)。现在,您可以通过设置Downloaderheader(字典)属性来设置自定义标头。

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

huangapple
  • 本文由 发表于 2023年5月29日 17:32:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76356187.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定