Byte array question

D

dan.winsor

Hi all,

I'm trying to write through SOAPpy in python to a Java implemented API.
The API for the method I want to use is as follows:

boolean added = SoapService.addAttachmentsToIssue(token,
issue.getKey(),
new String[]{fileName},
new byte[][]{getBytesFromFile(tmpFile)});

I've got everything covered except for the byte array. The byte array
should be holding the contents of the attachment(s) I want to send
thorugh the API. However, no matter how I try it, Java on the other
end doesn't like what I'm passing it there.

How can I mimic a byte array in python? Suggestions on things to try?
 
S

Sybren Stuvel

(e-mail address removed) enlightened us with:
I want to send thorugh the API. However, no matter how I try it,
Java on the other end doesn't like what I'm passing it there.

What have you tried and how did it fail?
How can I mimic a byte array in python?

Strings?

Sybren
 
D

Dan Winsor

Sybren said:
(e-mail address removed) enlightened us with:

What have you tried and how did it fail?

See below.

OK, I'll put that attempt up front. Here's a couple of tries:

<test code snippet>
fileobj = open('testfile.txt', mode='r')
chararray = fileobj.read()
fileobj.close()

soap.addAttachmentsToIssue(auth,'TST-4','testfile.txt',chararray)

<fails with>
SOAPpy.Types.faultType: <Fault soapenv:Server.userException:
org.xml.sax.SAXException: Found character data inside an array element
while deserializing: <SOAPpy.Types.structType detail at -1216265236>:
{'hostname': '<removed>', 'faultData': <SOAPpy.Types.structType
faultData at -1216226708>: {'exception': None, 'message': 'Found
character data inside an array element while deserializing'}}>

<'nother snippet>
fileobj = open('testfile.txt', mode='r')
chararray = array.array('c')
chararray.fromfile(fileobj, stat('testfile.txt').st_size)
fileobj.close()

soap.addAttachmentsToIssue(auth,'TST-4','testfile.txt',chararray)

<fails with>
SOAPpy.Types.faultType: <Fault soapenv:Server.userException:
org.xml.sax.SAXException: Found character data inside an array element
while deserializing: <SOAPpy.Types.structType detail at -1216482740>:
{'hostname': '<removed>', 'faultData': <SOAPpy.Types.structType
faultData at -1216075252>: {'exception': None, 'message': 'Found
character data inside an array element while deserializing'}}>

<'nother snippet>
fileobj = open('testfile.txt', mode='r')
chararray = array.array('c')
chararray.fromfile(fileobj, stat('testfile.txt').st_size)
#chararray = fileobj.read()
fileobj.close()

soap.addAttachmentsToIssue(auth,'TST-4','testfile.txt',[chararray])

This one "works" in that it runs, but the server on the other end gets
garbage unrelated to the test file.

I've tried a few other other ideas including other modes for the array
(b/B), but those are the highlights.
 
S

Sybren Stuvel

Dan Winsor enlightened us with:
This one "works" in that it runs, but the server on the other end gets
garbage unrelated to the test file.

Are you sure it is garbage? Have you tried changing byte order?

Sybren
 
D

Dan Winsor

Sybren said:
Dan Winsor enlightened us with:

Are you sure it is garbage? Have you tried changing byte order?

Ah, that I hadn't. Any pointers to doing that?
 
D

Dennis Lee Bieber

Hi all,

I'm trying to write through SOAPpy in python to a Java implemented API.
The API for the method I want to use is as follows:

boolean added = SoapService.addAttachmentsToIssue(token,
issue.getKey(),
new String[]{fileName},
new byte[][]{getBytesFromFile(tmpFile)});

I've got everything covered except for the byte array. The byte array
should be holding the contents of the attachment(s) I want to send
thorugh the API. However, no matter how I try it, Java on the other
end doesn't like what I'm passing it there.
Since I don't do Java, I could be misinterpreting the [][]... Given
that it looks like an array of array, maybe you need a Python list of
strings?

--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
M

Marc 'BlackJack' Rintsch

Dan Winsor said:
See below.


OK, I'll put that attempt up front. Here's a couple of tries:

<test code snippet>
fileobj = open('testfile.txt', mode='r')
chararray = fileobj.read()
fileobj.close()

soap.addAttachmentsToIssue(auth,'TST-4','testfile.txt',chararray)

<fails with>
SOAPpy.Types.faultType: <Fault soapenv:Server.userException:
org.xml.sax.SAXException: Found character data inside an array element
while deserializing: <SOAPpy.Types.structType detail at -1216265236>:
{'hostname': '<removed>', 'faultData': <SOAPpy.Types.structType
faultData at -1216226708>: {'exception': None, 'message': 'Found
character data inside an array element while deserializing'}}>

In the Java snippet from your initial post the `chararray` argument was an
*array* of `Byte` arrays. A string is just an one dimensional "byte
array". Maybe it helps if you put `chararray` into a list!?

Ciao,
Marc 'BlackJack' Rintsch
 
D

Dan Winsor

Marc said:
In the Java snippet from your initial post the `chararray` argument was an
*array* of `Byte` arrays. A string is just an one dimensional "byte
array". Maybe it helps if you put `chararray` into a list!?

Yup, thanks, that was one that I did try with no improvement:
fileobj = open('testfile.txt', mode='r')
chararray = fileobj.read()
fileobj.close()

soap.addAttachmentsToIssue(auth,'TST-4','scriptattach.txt',[chararray])

fails with:
SOAPpy.Types.faultType: <Fault Server.userException: No such operation
'addAttachmentsToIssue': <SOAPpy.Types.structType detail at
-1216379924>: {'hostname': '<removed>'}>

which is an uglier and less informative trace unfortunately. Thanks,
though.
 
D

Dan Winsor

John said:
You found array.array.byteswap() in the manual and rejected it because ...?

Unfortunately, this yielded similar results as not byte swapping it.
Thanks for the pointer, though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top