[Tutor] get bytes back from string representation?

Daniel daniel.chaowang at gmail.com
Mon Apr 13 11:03:56 CEST 2009

(also cc tutor)
Thank you, Alan. I found the solution.

the type of rawByte in SOAP is

<s:element minOccurs="0" maxOccurs="1" name="rawByte" type="s:base64Binary"

so I need to convert it back to ascii with binascii module, like:

>>> btxt = binascii.a2b_base64(page.rawByte)

then btxt can be treated as a normal string.


On Mon, Apr 13, 2009 at 3:32 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> "Daniel" <daniel.chaowang at gmail.com> wrote
> Caveat, I know nothing about SUDS.
>   rawByte = "PGh0bWw+PGhlYWQ+PG1ldGEgaHR0cC1lcXVpdj0iY29udGVudC10eXBlIiBjb2
>  the problem is I need to convert the rawByte from string to bytes, then
>> explain it as text with encoding (like "UTF-8").
> A string is a collection of bytes. What you see when you print a string is
> just the interpretation of those bytes as characters. So the real question
> is how do you want to interpret the bytes? What do the bytes represent?
> For example are they in a different character encoding, perhaps unicode?
> In that case simple changing the string encoding (and locale serttings?)
> should enable you  to print them as a string.
> Or do they represent binary data such as numbers or objects that need
> to be extracted and then turned into string representation. In that case
> you may need to use the struct module.
> It all depends on what the bytes actually represent.
> HTH,
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090413/876cdc8b/attachment-0001.htm>

More information about the Tutor mailing list