title: AttributeError:'bytes' object has no attribute 'encode'
body: <p>Trying to import a code from python2 to python 3 and this problem happens</p>
  
  <pre><code>    &lt;ipython-input-53-e9f33b00348a&gt; in aesEncrypt(text, secKey)
       43 def aesEncrypt(text, secKey):
       44     pad = 16 - len(text) % 16
  ---&gt; 45     text = text.encode("utf-8") + (pad * chr(pad)).encode("utf-8")
       46     encryptor = AES.new(secKey, 2, '0102030405060708')
       47     ciphertext = encryptor.encrypt(text)
  </code></pre>
  
  <blockquote>
    <p>AttributeError:'bytes' object has no attribute 'encode'</p>
  </blockquote>
  
  <p>If I remove <code>.encode("utf-8")</code> the error is "can't concat str to bytes". Apparently <code>pad*chr(pad)</code> seems to be a byte string. It cannot use <code>encode()</code></p>
  
  <pre><code>    &lt;ipython-input-65-9e84e1f3dd26&gt; in aesEncrypt(text, secKey)
       43 def aesEncrypt(text, secKey):
       44     pad = 16 - len(text) % 16
  ---&gt; 45     text = text.encode("utf-8") + (pad * chr(pad))
       46     encryptor = AES.new(secKey, 2, '0102030405060708')
       47     ciphertext = encryptor.encrypt(text)
  </code></pre>
  
  <blockquote>
    <p>TypeError: can't concat str to bytes</p>
  </blockquote>
  
  <p>However, the weird thing is that if i just try the part along. encode() works fine.</p>
  
  <pre><code>text = { 'username': '', 'password': '', 'rememberLogin': 'true' }
  text=json.dumps(text)
  print(text)
  pad = 16 - len(text) % 16 
  print(type(text))
  text = text + pad * chr(pad) 
  print(type(pad * chr(pad)))
  print(type(text))
  text = text.encode("utf-8") + (pad * chr(pad)).encode("utf-8") 
  print(type(text))
  
  {"username": "", "password": "", "rememberLogin": "true"}
  &lt;class 'str'&gt;
  &lt;class 'str'&gt;
  &lt;class 'str'&gt;
  &lt;class 'bytes'&gt;
  </code></pre>