2017-08-17 25 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()) 
相關問題