Input strings must be a multiple of 16 in length python 爬取时 AES 解码错误
程序员文章站
2022-07-10 15:25:02
...
环境: ubuntu18.04 python 3.6
错误产生的代码:
ts_req = request.Request(url=url, headers=headers)
ts_res = request.urlopen(ts_req)
if len(key):
cryptor = AES.new(key, AES.MODE_CBC, key)
with open(shu + '.mp4', 'ab') as f:
# 该处代码报错
f.write(cryptor.decrypt(ts_res.read()))
改正方式:
# from urllib import request
# 将上面的库替换成下面的库
import requests
# ts_req = request.Request(url=url, headers=headers)
# ts_res = request.urlopen(ts_req)
# 前两个替换成下面这个
ts_res = requests.get(url=url, headers=headers)
# f.write(cryptor.decrypt(ts_res.read()))
# 替换成
f.write(cryptor.decrypt(ts_res.content))
报错原因不知道,将urllib库更换成requests就可