无法使用收到的bytearray值
我正在使用Spyne开发肥皂Web服务器。 我已经在服务类中定义了以下方法:
@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}")
无论如何,我在ByTearray字段中的base64中发送了一些简单的PDF文件,但是我正在收到元组。 有没有办法在base64中重新构造曼坦甚至重新编写什么?
例如,我要发送一些以下内容:
JVBERi0xLjMNCiXi48/TDQoNCjEgMCBvYmoNCjw8DQovVHlwZSAvQ2F0YWxvZw0KL091dGxpb[...]
收到以下内容:
(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[...]
我已经在此堆栈溢出问题中阅读了答案: python spyne服务-Base64字符串逃脱了,但这并不能解决我的问题。我无法为bytearray定义避难所。
答案中的选项2不是我可以实现的最佳选择,因为在我的WSDL文件中共享的是
<xs:element name="attachment1_data" type="tns:add_ticket_attachment1_dataType" minOccurs="0" nillable="true" />
不是可行的数据类型名称。
提前致谢!
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: 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Bytearray用于抽象二进制编码不同协议中的差异。这就是为什么您会得到
bytes
对象的序列,如在这里。如果需要base64字符串,只需使用Unicode类型即可。
如果要使用base64字符串但需要使用bytearray,则可以尝试使用
bytearray(encoding = none)
,或对协议进行划分并覆盖ByteArray is used to abstract away binary encoding differences in different protocols. That's why you get a sequence of
bytes
objects, as documented here.If you want the base64 string, just use the Unicode type.
If you want the base64 string yet you NEED to use ByteArray, you can try using
ByteArray(encoding=None)
, or subclassing the protocol and overriding thebyte_array_from_element
function