aiohttp 显示错误 403 forbidden
aiohttp shows error 403 forbidden
我正在尝试从该网站下载 MP4 文件,但它不起作用,因为当我访问 link:
时,它显示错误 403 forbidden
这是我用来尝试下载文件的方法:
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。我怎样才能绕过它?
我明白了。看来我应该用这个:
async with aiohttp.ClientSession(headers={"Referer": "https://streamable.com"}) as cs:
需要 headers={"Referer": "https://streamable.com"}
部分。
对我来说,是我提出的请求太多太快了。我一放慢速度就没事了。
我正在尝试从该网站下载 MP4 文件,但它不起作用,因为当我访问 link:
时,它显示错误 403 forbidden这是我用来尝试下载文件的方法:
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。我怎样才能绕过它?
我明白了。看来我应该用这个:
async with aiohttp.ClientSession(headers={"Referer": "https://streamable.com"}) as cs:
需要 headers={"Referer": "https://streamable.com"}
部分。
对我来说,是我提出的请求太多太快了。我一放慢速度就没事了。