2017-08-17 62 views
-2

我看了很多其他的“问题,可能已经有你的答案”,但没有遇到任何直接命中在我遇到的问题上。TypeError:'str'不支持缓冲区接口 - 使用base64.b64encode

这里是我的Python 片段:

api_access_token = base64.b64encode('%s:' % api_access_token_setup) 

我收到以下错误:

TypeError: 'str' does not support the buffer interface

任何机会,有一个快速修复解决错误被提示。

+2

您需要一个* bytes *对象,而不是'str'。 –

+1

搜索时的专业提示:添加导致异常的功能。当我搜索异常和'64encode'时,Google在几秒钟内就有了重复。 –

回答

1

由于错误提示,您需要将bytes而不是str类型传递给b64encode。尝试编码您的字符串:

api_access_token = base64.b64encode(('%s:' % api_access_token_setup).encode()) 
相关问题