#10785 closed defect (fixed)

json-rpc ticket.putAttachment results in 'unicode' object has no attribute 'data'

Reported by: markuzmx Owned by: osimons
Priority: normal Component: XmlRpcPlugin
Severity: blocker Keywords: attachment
Cc: olemis Trac Release: 1.0


I'm trying to use the json-rcp ticket.putAttachment but when using it the call returns with this:

{    u'error': {    u'code': -32603,
                    u'message': u"ServiceException details : 'unicode' object has no attribute 'data'",
                    u'name': u'JSONRPCError'},
     u'id': None,
     u'result': None}

The data I'm sending is this:

{   'method': 'ticket.putAttachment',
    'params': [1359, 'add.png', 'description data here', 'b64encoded_data', True]}

I've replaced the b64encoded data with a simple string for brevity.

This results in the call to be unusable.

Attachments (0)

Change History (8)

comment:1 Changed 19 months ago by markuzmx

The easiest way to solve this is to check if the data argument is a string if it is then use it as it comes, if not, then try to use then check if the data member is present, and if not, then we don't know how to treat this and raise an error.

        if isinstance(data, basestring):
            attachment.insert(filename, StringIO(data), len(data))
            attachment.insert(filename, StringIO(, len(

comment:2 Changed 19 months ago by markuzmx

Btw, is important to decode from base64 the data.

comment:3 in reply to: ↑ description ; follow-up: Changed 19 months ago by olemis

  • Keywords attachment added

Please mention Python version .

comment:4 Changed 19 months ago by olemis

  • Summary changed from json-rcp ticket.putAttachment results in 'unicode' object has no attribute 'data' to json-rpc ticket.putAttachment results in 'unicode' object has no attribute 'data'

comment:5 in reply to: ↑ 3 Changed 19 months ago by markuzmx

Replying to olemis:

Please mention Python version .

I'm running Python 2.6.5

comment:6 Changed 19 months ago by osimons

Both wiki.putAttachment and ticket.putAttachment expects Binary input:

        yield (None,
               ((str, int, str, str, Binary, bool),
                (str, int, str, str, Binary)),

Why the wiki method reference documentation says...

string ticket.putAttachment(int ticket, string filename, string description,
                        base64 data, boolean replace=True)

... I don't know. Documenting Binary as base64 does not make it obvious that JSON-RPC really needs to use the class-hinting and post the data as {"__jsonclass__": ["binary", "<base64-encoded>"]}.

Example from test shows how it is done, see for instance RpcWikiTestCase.test_attachments() test in source:/xmlrpcplugin/trunk/tracrpc/tests/

For XML-RPC this makes it even less obvious that the input required is actually xmlrpclib.Binary type and not just the base64 string representation. Hmm, I'm sure the documentation used to say Binary and not base64. I wonder what changed and when...

Patch to fix documentation output most welcome ;-)

comment:7 Changed 19 months ago by osimons

The JsonTestCase.test_binary() test in source:/xmlrpcplugin/trunk/tracrpc/tests/ is a better example of how the JSON-RPC Binary works.

comment:8 Changed 18 months ago by osimons

  • Resolution set to fixed
  • Status changed from new to closed

(In [12546]) XmlRpcPlugin: Use more general DateTime and Binary terms for method documentation, seeing that the underlying implementation may differ between protocols. Closes #10785.

Add Comment

Modify Ticket

as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from osimons. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.