2016-08-17 9 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

私は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) 
関連する問題