Python Spyne Service - Base64 Strings Come Escaped
Solution 1:
First, some comments about the code you posted:
You must instantiate your types (i.e.
status = Status()
instead ofstatus = Status
). As it is, you're setting class attributes on theStatus
class. Not only this is just wrong, you're also creating race conditions by altering global state without proper locking.Does Jira have a way of creating issues with binary data? You can use
ByteArray
that handles base64 encoding/decoding for you. Note thatByteArray
gets deserialized as a sequence of strings.You can define a custom base64 type:
Base64String = String(pattern='[0-9a-zA-Z/+=]+')
... and use it instead of plain
String
together with validation to effortlessly reject invalid input.Instead of returning a "Status" object, I'd return nothing but raise an exception when needed (or you can just let the original exception bubble up). Exceptions also get serialized just like normal objects. But that's your decision to make as it depends on how you want your API to be consumed.
Now for your original question:
You'll agree that the right thing to do here is to fix whatever's escaping '\n' (i.e. 0x0a) as r"\n" (i.e. 0x5c 0x6e).
If you want to deal with it though, I guess the solution in your comment (i.e. base64attachment = base64attachment.decode('string-escape')
would be the best solution.
I hope that helps.
Best regards,
Post a Comment for "Python Spyne Service - Base64 Strings Come Escaped"