【问题标题】:AttributeError 'module' object has no attribute 'decodebytes'AttributeError 'module' 对象没有属性 'decodebytes'
【发布时间】:2019-05-15 12:49:52
【问题描述】:

我正在使用OpenCV 对图像进行一些处理。现在我需要将 base64 字符串转换为字节。在 Python-3.6 我可以使用 base64.decodebytes 但我在 Python-2.7 中找不到备用模块。 Python-2.7 中还有其他选择吗?

cvimg = cv2.imdecode(np_img_array, cv2.IMREAD_COLOR)
tmp_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = base64.b64encode(cv2.imencode('.jpg', tmp_img)[1])
img = base64.decodebytes(img)

注意:我使用 Python-2.7 作为我正在使用的模块之一尚未转换为 Python-3.6

【问题讨论】:

    标签: python python-2.7 base64


    【解决方案1】:

    Python 2 仍然内置了 base64 模块。 使用

    base64.standard_b64encode(s)
    #and
    base64.standard_b64decode(s)
    #Where 's' is an encoded string
    

    应该仍然有效。

    【讨论】:

      猜你喜欢
      • 2021-01-15
      • 2015-05-16
      • 2022-12-20
      • 2018-01-14
      • 2014-08-15
      • 2016-07-17
      • 2015-05-26
      • 2016-02-07
      • 1970-01-01
      相关资源
      最近更新 更多