[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2015-04-13 Thread Martin Panter

Martin Panter added the comment:

For the record, it looks like there were a few distinct but related problems 
here:

* Passing any StringIO object as the body is not supported (see 
https://docs.python.org/2/library/httplib.html#httplib.HTTPConnection.request),
 because no StringIO class implements the fileno() method.

* Passing a Python 2 natively implemented StringIO.StringIO instance triggers 
the same AttributeError exception as in Issue 15267, incompatibility with 
TemporaryFile objects.

* Even if HTTPConnection.request() did support calculating Content-Length for 
StringIO objects, it would still be wrong for chunk-encoded bodies. I think the 
lower-level endheaders() or send() methods should be used instead. Or see Issue 
12319, about adding chunked encoding for request().

--
nosy: +vadmium

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2015-04-12 Thread R. David Murray

R. David Murray added the comment:

Length computation is being dealt with in issue 23350.

--
resolution:  - duplicate
stage: needs patch - resolved
status: open - closed
superseder:  - Content-length is incorrect when request body is a list or tuple

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2014-02-03 Thread Mark Lawrence

Changes by Mark Lawrence breamore...@yahoo.co.uk:


--
nosy:  -BreamoreBoy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2013-04-03 Thread Mark Lawrence

Mark Lawrence added the comment:

@harobed if you still have a problem please provide more data as requested in 
msg138692.

--
nosy: +BreamoreBoy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2011-06-20 Thread Senthil Kumaran

Senthil Kumaran sent...@uthcode.com added the comment:

Hello Stephane,

 I use HTTPConnection to simulate Apple Finder WebDAV client.  When
 this WebDAV client do PUT request, it transmit data in chunked
 encoding mode and not set Content-Length HTTP field.
 
 Do you understand my context ?

Is the server at fault in not returning Content-Length?

Can you provide a full working snippet which demonstrates the bug you
are facing? I fear, if I am lacking some information to completely
determine what needs to be fixed (I understand the code change you
suggested, but also need to know why and under what practical
situation would code flow through that).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2011-06-15 Thread harobed

harobed steph...@harobed.org added the comment:

 But if the len information is available, why not return it?

I use HTTPConnection to simulate Apple Finder WebDAV client.
When this WebDAV client do PUT request, it transmit data in chunked encoding 
mode and not set Content-Length HTTP field.

Do you understand my context ?

Regards,
Stephane

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2011-06-15 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

The code you are suggesting patching is trying its best to return a length.  If 
that code needs to be fixed to not throw an error when confronted with a 
StringIO, then it should do its best to return a length.  Your original message 
on the ticket did not mention chunked encoding, and indeed that appears to be 
correct.  This bug doesn't appear, from what you have written and what I see in 
the 3.x code, to have anything to do with chunked encoding.

--
stage:  - needs patch
type:  - behavior

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2011-06-13 Thread harobed

New submission from harobed steph...@harobed.org:

Hi,

in httplib.HTTPConnection._send_request (Python 2.6)
in httplib.HTTPConnection._set_content_length (Python 2.7)
and http.client.HTTPConnection._set_content_length (Python 3.3)

there are something like that :

try:
thelen = str(len(body))
except TypeError as te:
# If this is a file-like object, try to
# fstat its file descriptor
try:
thelen = str(os.fstat(body.fileno()).st_size)
except (AttributeError, OSError):
# Don't send a length if this failed
if self.debuglevel  0: print(Cannot stat!!)


If I put StringIO object in body and I do :

 len(body)
AttributeError: StringIO instance has no attribute '__len__'

I haven't TypeError.

I think we need to replace :

try:
thelen = str(len(body))
except TypeError as te:

by :

if hasattr(body, read):
   ... # it's file-like object
else:
   ... # it's string object

What do you think about ?

--
components: Library (Lib)
messages: 138264
nosy: harobed
priority: normal
severity: normal
status: open
title: in HTTPConnection the are len(body) and TypeError catch exception to 
detect if body is file like object, this hack do work with StringIO object
versions: Python 2.6, Python 2.7, Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2011-06-13 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

fileno and stat won't work on a StringIO object.  So StringIO would need to be 
special cased to call getvalue.

--
nosy: +orsenthil, r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2011-06-13 Thread harobed

harobed steph...@harobed.org added the comment:

 fileno and stat won't work on a StringIO object.  So StringIO would need to 
 be special cased to call getvalue.

Yes, but it isn't important in chunk transfer encoding.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2011-06-13 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

But if the len information is available, why not return it?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

2011-06-13 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
versions: +Python 3.2 -Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12327
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com