Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > HTTPConnection.send

Reply
Thread Tools

HTTPConnection.send

 
 
dspublic@freemail.hu
Guest
Posts: n/a
 
      03-29-2013
Hi!

I have a problem with HTTPConnection object send() method (pyver3.3.1). I want to send data from file-like object with HTTPConnection.send( f ), and Iget a "data should be a bytes-like object or an iterable, ..." exception. I have investigated a send method, and discovered a problem: if data has a read attribute, send it , and try send it again with self.sock.sendall(data). My opinion is need an "else" after the "if hasattr(data, "read")"

Please, somebody help me. Does it a real BUG or my mistake?

http.client.py >

if hasattr(data, "read") :
if self.debuglevel > 0:
print("sendIng a read()able")
encode = False
try:
mode = data.mode
except AttributeError:
# io.BytesIO and other file-like objects don't have a `mode`
# attribute.
pass
else:
if "b" not in mode:
encode = True
if self.debuglevel > 0:
print("encoding file using iso-8859-1")
while 1:
datablock = data.read(blocksize)
if not datablock:
break
if encode:
datablock = datablock.encode("iso-8859-1")
self.sock.sendall(datablock)
ELSE: #!!!! i guess missing !!!!
try:
self.sock.sendall(data)
except TypeError:
if isinstance(data, collections.Iterable):
for d in data:
self.sock.sendall(d)
else:
raise TypeError("data should be a bytes-like object "
"or an iterable, got %r" % type(data))
 
Reply With Quote
 
 
 
 
dspublic@freemail.hu
Guest
Posts: n/a
 
      03-29-2013
Problematical python versions: 3.2+ (2.x, 3.0, 3.1 ok)
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      03-29-2013
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I have a problem with HTTPConnection object send() method (pyver3.3.1). I
> want to send data from file-like object with HTTPConnection.send( f ), and
> I get a "data should be a bytes-like object or an iterable, ..."
> exception. I have investigated a send method, and discovered a problem: if
> data has a read attribute, send it , and try send it again with
> self.sock.sendall(data). My opinion is need an "else" after the "if
> hasattr(data, "read")"
>
> Please, somebody help me. Does it a real BUG or my mistake?


I think your analysis is correct. Please file a bug report on
<http://bugs.python.org>.

> http.client.py >
>
> if hasattr(data, "read") :
> if self.debuglevel > 0:
> print("sendIng a read()able")
> encode = False
> try:
> mode = data.mode
> except AttributeError:
> # io.BytesIO and other file-like objects don't have a
> # `mode` attribute.
> pass
> else:
> if "b" not in mode:
> encode = True
> if self.debuglevel > 0:
> print("encoding file using iso-8859-1")
> while 1:
> datablock = data.read(blocksize)
> if not datablock:
> break
> if encode:
> datablock = datablock.encode("iso-8859-1")
> self.sock.sendall(datablock)
> ELSE: #!!!! i guess missing !!!!
> try:
> self.sock.sendall(data)
> except TypeError:
> if isinstance(data, collections.Iterable):
> for d in data:
> self.sock.sendall(d)
> else:
> raise TypeError("data should be a bytes-like object "
> "or an iterable, got %r" % type(data))


 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      03-29-2013
On Fri, Mar 29, 2013 at 11:27 PM, <(E-Mail Removed)> wrote:
> I have a problem with HTTPConnection object send() method (pyver3.3.1). Iwant to send data from file-like object with HTTPConnection.send( f ), andI get a "data should be a bytes-like object or an iterable, ..." exception.. I have investigated a send method, and discovered a problem: if data has a read attribute, send it , and try send it again with self.sock.sendall(data). My opinion is need an "else" after the "if hasattr(data, "read")"
>
> Please, somebody help me. Does it a real BUG or my mistake?


Yeah, I think you may be right on that. Changeset 67046 added the try
block, and removed the else. I'd raise this on the tracker; I'd say
the removal of else was purely accidental.

ChrisA
 
Reply With Quote
 
dspublic@freemail.hu
Guest
Posts: n/a
 
      03-29-2013
Thanx for confirmations...

I have reported http://bugs.python.org/issue17575
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments