Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: python3.0 base64 error

Reply
Thread Tools

Re: python3.0 base64 error

 
 
MRAB
Guest
Posts: n/a
 
      01-17-2009
yang michael wrote:
> I use base64 module on python3.0
> like:
>
> import base64
> b="hello world"


Try:

b = b"hello world"

instead.

> a=base64.b64encode(b)
> print(a)
>
> but when i run it,it catch a error:
> Traceback (most recent call last):
> File "/home/jackie-yang/yd5m19/pythonstudy/test.py", line 4, in <module>
> a=base64.b64encode(b)
> File "/usr/local/lib/python3.0/base64.py", line 56, in b64encode
> raise TypeError("expected bytes, not %s" % s.__class__.__name__)
> TypeError: expected bytes, not str
>
>
>
> and also the document's example:
>
>>>> import base64
>>>> encoded = base64.b64encode('data to be encoded')

>
>>>> encoded

> 'ZGF0YSB0byBiZSBlbmNvZGVk'
>>>> data = base64.b64decode(encoded)

>
>>>> data

> 'data to be encoded'
>
> can not run too.
>
> what happen?
>

As the traceback says, it needs bytes, not string. Perhaps the example
would've been clearer as:

>>> import base64
>>> encoded = base64.b64encode(b'data to be encoded')


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error on base64.b64decode() ?! Christoph Krammer Python 2 10-14-2007 04:26 AM
Re: Error on base64.b64decode() ?! Jean-Paul Calderone Python 0 10-12-2007 03:09 PM
Base64 Error/Hotfix? =?Utf-8?B?Si4gTmFkYWw=?= ASP .Net 2 11-07-2005 07:45 PM
ASP.NET + C# + TabletPC ActiveX Control + JavaScript = Base64 to GIF Kunal ASP .Net 0 10-02-2003 11:23 PM
base64 enc/dec problem PCH ASP .Net 2 07-01-2003 06:55 PM



Advertisments