aiohttp显示错误403 forbidden

时间:2017-10-22 23:26:01

标签: python python-3.x aiohttp

我试图从这个网站下载MP4文件,但它不起作用,因为它在我访问该链接时显示错误403被禁止:

这是我用来尝试下载文件的内容:

async with aiohttp.ClientSession() as cs:
    async with cs.get('https://cdn-e1.streamable.com/video/mp4/kphjz.mp4') as r:
        if r.status == 200:
            img = await r.read()
            with open('C:/xxxx/xxxx/xxxx/xxxx/Streamables/' + url.split('/')[-1], 'wb') as f:
                f.write(img)
                f.close()
                print('Downloaded {0}'.format(url.split('/')[-1]))

它没有做任何事,因为r.status不等于200而是403.我怎么能绕过这个呢?

2 个答案:

答案 0 :(得分:1)

我明白了。看起来我应该用这个:

async with aiohttp.ClientSession(headers={"Referer": "https://streamable.com"}) as cs:

需要headers={"Referer": "https://streamable.com"}部分。

答案 1 :(得分:0)

对我来说,我提出太多请求的速度太快了。我放慢速度,一切都很好。

相关问题