I am trying to use MSMQ to send a NMEA message to a C# sever. This NMEA message (string) is to be base64 encoded and then sent as a byte array.
The problem I am running into is that in MSMQ my byte array is showing as:
03 00 00 00 00 00 00 00 ........
3C 00 00 00 00 00 00 00 <.......
01 00 00 00 00 00 00 00 ........
03 00 00 00 00 00 00 00 ........
3F 00 00 00 00 00 00 00 ?.......
01 00 00 00 00 00 00 00 ........
03 00 00 00 00 00 00 00 ........
78 00 00 00 00 00 00 00 x.......
Oppose to what I'm looking for:
3C 3F 78 6D 6C 20 76 65 <?xml ve
72 73 69 6F 6E 3D 22 31 rsion="1
2E 30 22 3F 3E 0D 0A 3C .0"?>..<
62 61 73 65 36 34 42 69 base64Bi
A sample of my code:
# base64 encode the message
b64_nmea = base64.b64encode(nmea)
# Adding xml prolog.. used by the server
b64_nmea = '<?xml version="1.0"?>..<base64Binary>' + b64_nmea + '==</base64Binary>'
# creates a byte array from b64_nmea
bytearray_nmea = bytearray(b64_nmea)
# Then to send the message:
qinfo = win32com.client.Dispatch("MSMQ.MSMQQueueInfo")
computer_name = os.getenv('COMPUTERNAME')
qinfo.FormatName = "direct=os:" + computer_name + "\\Private$\\test"
queue = qinfo.Open(2, 0)
msg = win32com.client.Dispatch("MSMQ.MSMQMessage")
msg.Label = "test"
msg.Body = bytearray_nmea
msg.Send(queue)
queue.Close()
My question is: where do these null values come from and are they caused by an error in the byte array creation or is my method for dispatching to MSMQ going wonky?
I have tried quite a few variations with bytearray()
.. the above code is going back to one of my less "extreme" attempts. Any insight is appreciated.
This problem can be solved by using subprocess.Popen()
on an exe that queues my messages, however it would be great to have a solution using only Python.