根据错误提示,可以判断在进行base64编码时出现了非法字符“-”,需要将其删除或替换后再进行编码。以下是Python代码中对非法字符进行替换的示例:
import base64
# 准备原始数据
data = b'test-data'
# 进行base64编码
try:
base64_encoded = base64.b64encode(data.replace(b'-', b'_')) # 将'-'替换为'_'
print(base64_encoded)
except Exception as e:
print(e)
在以上示例中,对原始数据中的“-”进行了替换(使用“_”代替),再进行base64编码,成功解决了“Illegal base64 character 2d”的错误提示。