problem with PORTABLE_BYTES and python3.2

Asked by Ottavio Campana on 2012-01-23

Hi, I'm trying to realize a website that sends a binary file to a
server from the client (both client and server are ladon-based)

Thus, I used the PORTABLE_BYTES data type and tried to send a pdf.

The command I'm using on the client is


I get this error

TypeError: b'%PDF-1.6\r%\xe2\xe3\xcf\xd3\r\n1235...' is not JSON

I digged a bit in the traceback of my application and what I found is that ladon fails when it uses the json encoder from the python library. Particularly, i seems not to be able to encode the bytes data type (you can see it in the traceback, when it refers to /usr/lib/python3.2/json/ , line 170). I checked this also in python 2.7, but in that version the json encoder is able to deal with the str data type.

So my question is: did you ever see any regression with PORTABLE_BYTES and python3? Or am I making a mistake?

Thank you for your help,


Here's my application traceback

    File "/tmp/a/lib/python3.2/site-packages/pyramid_debugtoolbar-0.9.7-py3.2.egg/pyramid_debugtoolbar/panels/", line 55, in resource_timer_handler

    result = handler(request)

    File "/tmp/a/lib/python3.2/site-packages/pyramid-1.3a3-py3.2.egg/pyramid/", line 20, in excview_tween

    response = handler(request)

    File "/tmp/a/lib/python3.2/site-packages/pyramid-1.3a3-py3.2.egg/pyramid/", line 164, in handle_request

    response = view_callable(context, request)

    File "/tmp/a/lib/python3.2/site-packages/pyramid-1.3a3-py3.2.egg/pyramid/config/", line 343, in viewresult_to_response

    result = view(context, request)

    File "/tmp/a/lib/python3.2/site-packages/pyramid-1.3a3-py3.2.egg/pyramid/config/", line 426, in _requestonly_view

    response = view(request)

    File "/tmp/a/projects/myproject/myproject/views/backoffice/", line 19, in index

    return render_view_to_response(None, request, name=view_to_be_called)

    File "/tmp/a/lib/python3.2/site-packages/pyramid-1.3a3-py3.2.egg/pyramid/", line 77, in render_view_to_response

    return view(context, request)

    File "/tmp/a/lib/python3.2/site-packages/pyramid-1.3a3-py3.2.egg/pyramid/config/", line 316, in rendered_view

    result = view(context, request)

    File "/tmp/a/lib/python3.2/site-packages/pyramid-1.3a3-py3.2.egg/pyramid/config/", line 426, in _requestonly_view

    response = view(request)

    File "/tmp/a/projects/myproject/myproject/views/backoffice/", line 266, in file_new

    i = eval (command)

    File "<string>", line 1, in <module>

    File "<string>", line 2, in placeholder

    File "/tmp/a/lib/python3.2/site-packages/ladon-0.6.5-py3.2.egg/ladon/clients/", line 180, in call_method

    jsonwsp_response = self.post_request(json.dumps(data))

    File "/usr/lib/python3.2/json/", line 224, in dumps

    return _default_encoder.encode(obj)

    File "/usr/lib/python3.2/json/", line 188, in encode

    chunks = self.iterencode(o, _one_shot=True)

    File "/usr/lib/python3.2/json/", line 246, in iterencode

    return _iterencode(o, 0)

    File "/usr/lib/python3.2/json/", line 170, in default

    raise TypeError(repr(o) + " is not JSON serializable")

Question information

English Edit question
ladon Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Best jsgaarde (jakob-simon-gaarde) said : #1

Hi Ottavio.

I can see you are using the jsonwsp protocol, so why not use the attachment type?

Best Regards
Jakob Simon-Gaarde

Ottavio Campana (ottavio) said : #2

Are attachment supported in the last version of ladon for soap?

Do you think that the problem with bytes data type can be a bug?

I'll try attachments anyway

Thank you,


jsgaarde (jakob-simon-gaarde) said : #3

Btw, there is a full example on using attachments in the official ladon-examples pack:
/ Jakob

jsgaarde (jakob-simon-gaarde) said : #4

SOAP has very bad support for attachments, and I have found that SOAP actually doesn't support the attachment features that Ladon aims for.
However, it is actually possible cheat a little. If you are using a SOAP client that can add binary multiparts freely.
If you add your attachment as an application/octet-stream multipart, without mentioning the ladon.types.attachment in the service module, you can access the attachment from your service method using the kw['attachment'] key:


In short:
* Ladon handles multipart requests even though attachments are not defined for a certain method.
* Ladon takes care of attachments even though the SOAP interface does not support it.
* All you need is a client that can send a SOAP request as a multi-part request

Best Regards
Jakob Simon-Gaarde

Ottavio Campana (ottavio) said : #5

Thanks jsgaarde, that solved my question.

Ottavio Campana (ottavio) said : #6

I converted my code to use attachment, it works.