Determine size of string in bytes

B

breal

Forgive me for this question which is most likely stupid...

How do I determine the number of bytes a string takes up? I have a
soap server that is returning a serialized string. It seems that when
the string goes over 65978 characters it does not return to the soap
client. Instead I get an error:
error: (35, 'Resource temporarily unavailable')

This makes me think the problem exists on the soap client side with
some sort of max return length. If I knew how many bytes the 65978
character string was, then I could try to up this value.

Thanks.
 
G

Gabriel Genellina

Forgive me for this question which is most likely stupid...

How do I determine the number of bytes a string takes up? I have a
soap server that is returning a serialized string. It seems that when
the string goes over 65978 characters it does not return to the soap
client. Instead I get an error:
error: (35, 'Resource temporarily unavailable')

len(x)?
Or do you wan to know how many bytes will have an unicode object when
encoded in a certain encoding? The only way is to actually encode it and
take the length.
 
J

John Machin

Forgive me for this question which is most likely stupid...

The contents of your question are not stupid. The subject however does
invite a stupid answer like: len(the_string).

Disclaimer: I know nothing about SOAP except that it's usually
capitalised :) Now read on:
How do I determine the number of bytes a string takes up? I have a
soap server that is returning a serialized string.

Serialised how? UTF-8?
It seems that when
the string goes over 65978 characters it does not return to the soap
client.

Why does it seem so? How did you arrive at such a precise limit?
Instead I get an error:
error: (35, 'Resource temporarily unavailable')

Is this error from the client or the server? Any error or logfile
record from the other side?

Is there anything in the documentation about maximum sizes?
This makes me think the problem exists on the soap client side with
some sort of max return length.

Think? Can't you verify this by inspecting the source?
If I knew how many bytes the 65978
character string was, then I could try to up this value.

How do you know the string is 65978 characters? If you are debugging
the server, can't you do len(serialise(the_65978_char_string))?

65978? Are you sure? Looks suspiciously close to 65535 aka 0xFFFF aka
(2 ** 16 - 1 ) to me.

If you have the server, you presumably have the source code for both
client and server. Some options for you:

(1) Look at the traceback(s), look at the source code, nut it out for
yourself. If there is some kind of max other than an implicit 16-bit
limitation in the client code, it shouldn't be too hard to find.

(2) Post the traceback(s) here, along with other details that might be
useful, like what SOAP server s/w you are using, what version of
Python, what platform.

HTH,

John
 
C

castironpi

The contents of your question are not stupid. The subject however does
invite a stupid answer like: len(the_string).

Disclaimer: I know nothing about SOAP except that it's usually
capitalised :) Now read on:


Serialised how? UTF-8?


Why does it seem so? How did you arrive at such a precise limit?


Is this error from the client or the server? Any error or logfile
record from the other side?

Is there anything in the documentation about maximum sizes?




Think? Can't you verify this by inspecting the source?


How do you know the string is 65978 characters? If you are debugging
the server, can't you do len(serialise(the_65978_char_string))?

65978? Are you sure? Looks suspiciously close to 65535 aka 0xFFFF aka
(2 ** 16 - 1 ) to me.

If you have the server, you presumably have the source code for both
client and server. Some options for you:

(1) Look at the traceback(s), look at the source code, nut it out for
yourself. If there is some kind of max other than an implicit 16-bit
limitation in the client code, it shouldn't be too hard to find.

(2) Post the traceback(s) here, along with other details that might be
useful, like what SOAP server s/w you are using, what version of
Python, what platform.

I'm dying to find out.
 
B

breal

The contents of your question are not stupid. The subject however does
invite a stupid answer like: len(the_string).

Disclaimer: I know nothing about SOAP except that it's usually
capitalised :) Now read on:


Serialised how? UTF-8?

Yes. I meant to include that. I did not understand that len()
returned the actual byte length of a UTF-8 encoded string.
Why does it seem so? How did you arrive at such a precise limit?

I actually just wrote a test that would call a function on the SOAP
server (SOAPpy) that would increase or decrease the test length based
on the previous result until it found x, x+1 where x characters didn't
fail, but x+1 did. x ended up being 65978. The string I happen to be
encoding in this case has all ascii characters so it is the same for
both encodings.

Is this error from the client or the server? Any error or logfile
record from the other side?

This is an error on the server. The client is actually written in
PHP.

There is no log file, but there is a traceback...
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/SocketServer.py", line 464, in process_request_thread
self.finish_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/SocketServer.py", line 254, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/SocketServer.py", line 522, in __init__
self.handle()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/BaseHTTPServer.py", line 316, in handle
self.handle_one_request()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/BaseHTTPServer.py", line 310, in handle_one_request
method()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/SOAPpy/Server.py", line 545, in do_POST
self.wfile.write(resp)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/socket.py", line 262, in write
self.flush()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/socket.py", line 249, in flush
self._sock.sendall(buffer)
error: (35, 'Resource temporarily unavailable')
----------------------------------------


Is there anything in the documentation about maximum sizes?

I googled my brains out looking for anything about maximum size both
on the Python SOAP server, and the PHP SOAP client.
Think? Can't you verify this by inspecting the source?

I haven't inspected the source, but I have inspected the
documentation. No luck in finding anything about it. I suppose I
could download the client source and see what I can see.
How do you know the string is 65978 characters? If you are debugging
the server, can't you do len(serialise(the_65978_char_string))?

65978? Are you sure? Looks suspiciously close to 65535 aka 0xFFFF aka
(2 ** 16 - 1 ) to me.

If you have the server, you presumably have the source code for both
client and server. Some options for you:

(1) Look at the traceback(s), look at the source code, nut it out for
yourself. If there is some kind of max other than an implicit 16-bit
limitation in the client code, it shouldn't be too hard to find.

(2) Post the traceback(s) here, along with other details that might be
useful, like what SOAP server s/w you are using, what version of
Python, what platform.

See traceback above.
SOAPpy
Python 2.5
OSX Server


Thanks for the response John.
 

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,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top