2

I have the following error when I trying to send Zipfile content via suds method

'ascii' codec can't decode byte 0x8c in position 10: ordinal not in range(128)

Here is my code:

try:
    project_archive = open(os.path.join(settings.MEDIA_ROOT, 'zip/project.zip'), "rb")
    data = project_archive.read()
    client = Client(settings.UPLOAD_PROJECT_WS_URL)
    client.service.uploadProject(data)
except Exception as e:
    return HttpResponse(e)
else:
    return HttpResponse("Project was exported")

3 Answers3

1

suds doesn't support soap file attachment (not last time I checked, it has been a while).

Work around here: https://fedorahosted.org/suds/attachment/ticket/350/soap_attachments.2.py

or use a different library

user1474424
  • 657
  • 1
  • 5
  • 18
1

Assuming that in the WSDL the argument type is xsd:base64Binary, you need to:

client.service.uploadProject(base64.b64encode(data))    

In my case the sever was written in JAX-WS and the function argument type was Byte[] and Base64 worked for me

Benav
  • 468
  • 5
  • 5
0

The problem seems to be simply that you are trying to read a unicode formatted file using ascii codec. Refer to http://docs.python.org/2/howto/unicode.html for the official documentation on unicode. You can also look at Unicode (UTF-8) reading and writing to files in Python for a similar discussion.

In short for your problem the following code should work:

import codecs
project_archive = codecs.open(os.path.join(settings.MEDIA_ROOT, 'zip/project.zip'), 
                              "rb", "utf-8")
data = project_archive.read()

In the above solution its assumed that the unicode encoding used is utf-8. If some other codec (for example ISO-8859-1) is being used substitute that for the utf-8.

Community
  • 1
  • 1
goofd
  • 2,028
  • 2
  • 21
  • 33