Cadair / parfive

An asyncio based parallel file downloader for Python 3.8+

Home Page:https://parfive.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

User specified headers are ignored if User-Agent isn't specified

karl0ss opened this issue · comments

Maybe I'm missing something but I am trying to pass in headers as such -

dl = Downloader(
    headers=dict(one=1, two=2, three=3)
)

But they do not seem to be getting set and in dl.headers all i see is
{'User-Agent': 'parfive/1.5.1 aiohttp/3.8.1 python/3.8.1'}

Hope someone can shed some light on what I am doing wrong...

Thanks

I would seem that you have to include a User-Agent as one of your passed in headers or it doesn't work.

Yeah, I would say that's a bug, this line here:

if headers is None or 'User-Agent' not in headers:
self.headers = {
'User-Agent': f"parfive/{parfive.__version__} aiohttp/{aiohttp.__version__} python/{sys.version[:5]}"}

should update the headers dict if it exists but user agent isn't in it rather than overwrite it.