You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mojo在线JupyterLab中base64.b64decode报错问题求助

Mojo base64解码函数缺失问题解决办法

问题重现

使用Mojo的base64模块编码正常:

from base64

print(base64.b64encode("This is a "))
>>VGhpcyBpcyBhIA==

但调用b64decode时触发报错:

print(base64.b64decode("VGhpcyBpcyBhIA=="))

报错信息:

error: Expression [99]:20:17: package 'base64' does not contain 'b64decode'
    print(base64.b64decode("VGhpcyBpcyBhIA=="))
                ^

expression failed to parse (no further compiler diagnostics)

问题原因

Mojo的base64模块目前仅实现了编码相关函数(如b64encode),解码函数(包括b64decode)暂未完成开发,属于已知的功能缺口。

临时解决方案

利用Mojo对Python库的无缝调用能力,直接使用Python的base64模块完成解码:

from python import Python

# 导入Python的base64模块
let py_base64 = Python.import_module("base64")
# 解码并转换为字符串输出
print(py_base64.b64decode("VGhpcyBpcyBhIA==").decode("utf-8"))
>>This is a 

相关讨论内容(翻译自官方讨论)

  • 已有用户反馈Mojo的base64模块缺少b64decode及b64decodebytes等解码函数。
  • 官方团队表示,解码功能属于后续规划内容,当前优先完成了编码功能的开发。
  • 官方明确建议,在解码功能正式上线前,用户可通过调用Python的base64库作为临时替代方案。

内容的提问来源于stack exchange,提问作者Jesse Sealand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 03:34:52