2016-08-17 59 views
0
if wb == 'Encode a sentence' or wb == 'encode a sentence': 
    print("Please enter the Sentence...") 
    str = input() 
    str = str.encode('base64','strict') 
    print(str) 

它告诉我,它不能是字节,它们应该是字符串...任何帮助表示赞赏!我无法编码我的输入

+2

您正在使用什么版本的Python? –

+0

Im using python 3.5.0 –

+0

在附注中,最好使用不同的变量名称而不是'str',因为这是一个Python内置的函数,可用于诸如'str.encode('my字符串')' –

回答

1

试试这个:

from base64 import b64encode 
b64encode(wb.encode()) 

也为你如果线路使用

if wb.lower() == 'encode a sentence': 
+1

谢谢!很多我的朋友 –

1

你可以试试这个:

import base64 

if wb == 'Encode a sentence' or wb == 'encode a sentence': 
    print("Please enter the Sentence...") 
    str = input() 
    base64.b64encode(bytes(str, 'utf-8')) 
    print(str)