arskom / spyne

A transport agnostic sync/async RPC library that focuses on exposing services with a well-defined API using popular protocols.
http://spyne.io
Other
1.13k stars 313 forks source link

Unable to use ByteArray value received #688

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi, I'm developing a soap web server with spyne. I've defined the following method inside a Service class:

@rpc(String, String, String, String, String, DateTime, String, String,
         String, Integer32, ByteArray, _returns=ResponseCode)
    def add_ticket(ctx, t_id, text, cat1, cat2, cat3, date, user, service, attachment1_name, attachment1_size, attachment1_data):
        logging.info(f"Received ticket: {t_id} with category {cat1}/{cat2}/{cat3} under service {service}")

        logging.info(f"Attachment 1: {attachment1_data}")

Anyway I'm sending some simple pdf file encoded in base64 in the ByteArray field, but I'm receiving a tuple. Is there a way to mantain or even re-encode in base64 what is received?

For example, I'm sending something that start with: JVBERi0xLjMNCiXi48/TDQoNCjEgMCBvYmoNCjw8DQovVHlwZSAvQ2F0YWxvZw0KL091dGxpb[...]

and receiving something that starts with: (b'%PDF-1.4\n%\xc3\xa4\xc3\xbc\xc3\xb6\xc3\x9f\n2 0 obj\n<</Length 3 0 R/Filter/FlateDecode>>\nstream\nx\x9c\xad\x1aM\x8b[...]

I've read the answer in this stack overflow question: https://stackoverflow.com/questions/15356357/python-spyne-service-base64-strings-come-escaped but it doesn't resolve my problem. I'm not able to define the deserialization method for ByteArray.

The option 2 in the answer is not the best that I can implement because in my wsdl file to share there would be <xs:element name="attachment1_data" type="tns:add_ticket_attachment1_dataType" minOccurs="0" nillable="true" /> that is not a feasible data type name.

Thanks in advance!

plq commented 2 years ago

Is there a bug report here? The base64 conversion is documented behavior. Please reopen if I missed something.

ghost commented 2 years ago

Is there a bug report here? The base64 conversion is documented behavior. Please reopen if I missed something.

I know is documented. I'm asking if is there a way to manage what is received by the server, because I need to forward the content of the request to another server via REST api invocation.

So, from what I receive is there a way to pass from 'a sequence of string' to base64 again?

plq commented 2 years ago

see #689