By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,600 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,600 IT Pros & Developers. It's quick & easy.

Byte array question

P: n/a
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?

Jul 13 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Sybren Stuvel wrote:
da********@gmail.com 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?
See below.
How can I mimic a byte array in python?

Strings?
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.

Jul 13 '06 #2

P: n/a

Sybren Stuvel wrote:
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?
Ah, that I hadn't. Any pointers to doing that?

Jul 14 '06 #3

P: n/a
On 14/07/2006 10:41 AM, Dan Winsor wrote:
Sybren Stuvel wrote:
>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?

Ah, that I hadn't. Any pointers to doing that?
You found array.array.byteswap() in the manual and rejected it because ...?

Jul 14 '06 #4

P: n/a

John Machin wrote:
On 14/07/2006 10:41 AM, Dan Winsor wrote:
Sybren Stuvel wrote:
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?
Ah, that I hadn't. Any pointers to doing that?

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

Jul 14 '06 #5

P: n/a
In <11**********************@b28g2000cwb.googlegroups .com>, Dan Winsor
wrote:
Sybren Stuvel wrote:
>da********@gmail.com 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?

See below.
How can I mimic a byte array in python?

Strings?

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
Jul 14 '06 #6

P: n/a
Marc 'BlackJack' Rintsch wrote:
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.

Jul 14 '06 #7

P: n/a

John Machin wrote:
On 14/07/2006 10:41 AM, Dan Winsor wrote:
Sybren Stuvel wrote:
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?
Ah, that I hadn't. Any pointers to doing that?

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.

Jul 14 '06 #8

P: n/a
Nevermind. Did it in Java. Thanks anyway to all who gave suggestions.

Jul 14 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.