Base64 encoding/decoding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oliver Kurz

    Base64 encoding/decoding

    Hello,

    I have a problem by converting a string to base64 and back again.

    I have a string with german special chars like äöüß.

    This string i convert with base64str=base6 4.encode('äöüß' ) into a base64 representation.

    Backwards I got an error:


    binascii.Error: Incorrect padding

    I use base64.decode(b ase64str).

    The charset I use is iso-iso-8859-1.

    What am I doing wrong?

    Is there somewhere a good tutorial bei encoding and decoding with different charsets?
    I get text from different sources and i have to decode it and convert it at the end to utf-8.




    -- 
    --
    Oliver Kurz


  • Riccardo Galli

    #2
    Re: Base64 encoding/decoding

    On Wed, 17 Mar 2004 17:02:25 +0100, Oliver Kurz wrote:
    [color=blue]
    > Hello,
    >
    > I have a problem by converting a string to base64 and back again.
    >
    > I have a string with german special chars like äöüß.
    >
    > This string i convert with base64str=base6 4.encode('äöüß' ) into a base64
    > representation.[/color]

    encode you string in utf
    [color=blue][color=green][color=darkred]
    >>> lol='äöüß'.deco de('iso-8859-1').encode('UTF 8')[/color][/color][/color]
    '\xc3\xa4\xc3\x b6\xc3\xbc\xc3\ x9f'[color=blue][color=green][color=darkred]
    >>> base64.decodest ring(base64.enc odestring(lol))[/color][/color][/color]
    '\xc3\xa4\xc3\x b6\xc3\xbc\xc3\ x9f

    this should work

    Ciao,
    Riccardo

    --
    -=Riccardo Galli=-

    _,e.
    s~ ``
    ~@. ideralis Programs
    .. ol
    `**~ http://www.sideralis.net

    Comment

    Working...