base64.encodestring scheitern in python 3

Folgende Stück code erfolgreich ausgeführt über ein python-2 Maschine:

base64_str = base64.encodestring('%s:%s' % (username,password)).replace('\n', '')

Ich versuche die Portierung über Python 3, aber wenn ich tun, damit ich die folgende Fehlermeldung auftreten:

>>> a = base64.encodestring('{0}:{1}'.format(username,password)).replace('\n','')
Traceback (most recent call last):
  File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 519, in _input_type_check
    m = memoryview(s)
TypeError: memoryview: str object does not have the buffer interface

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 548, in encodestring
    return encodebytes(s)
  File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 536, in encodebytes
    _input_type_check(s)
  File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 522, in _input_type_check
    raise TypeError(msg) from err
TypeError: expected bytes-like object, not str

Ich habe versucht, die Suche Beispiele für encodestring Verwendung, aber nicht in der Lage zu finden, ein gutes Dokument. Übersehe ich hier etwas offensichtliches? Ich führe dies auf RHEL-2.6.18-371.11.1.el5

InformationsquelleAutor Vinay Pai | 2015-06-30
Schreibe einen Kommentar