views:

152

answers:

2

hi,

I am using SUDS to talk with a web service written by C#. The service recieves a url, crawls its web page, then return its content as byte[].

its type in SOAP is:

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

sample client codes:

>>> from suds.client import Client
>>> url = "http://WSServer/Service1.asmx?wsdl"
>>> client = Client(url)
>>> page = client.service.GetURLContent("http://www.google.co.uk")
>>> print page
(CrawlResult){
   crawStatus = "SUCC"
   rawByte = "PGh0bWw+PGhlYWQ+PG1ldGEgaHR0cC1lcXVpdj0iY29udGVudC10eXBlIiBjb2 ... "

the problem is how to convert the rawByte from string to bytes, then explain it as text with encoding (like "ascii").

I am not clear with that.

Thanks, Daniel.

+3  A: 

As the SOAP element says, the bytes are base64-encoded.

To decode, use the python module base64.

gnud
+1  A: 

thanks, gnud.

I found the solution. I need to convert it back to string with binascii module, like:

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

then btxt can be treated as a normal string.

Daniel Wang