[issue5038] urrlib2/httplib doesn't reset file position between requests
Martin Panter
report at bugs.python.org
Sat Feb 16 02:13:24 EST 2019
Martin Panter <vadmium+py at gmail.com> added the comment:
For 3.7+ (where iterable objects are supported), I suggest:
1. Document the problem as a limitation of handlers like AbstractBasicAuthHandler, and consider raising an exception instead of trying to upload a file or iterable a second time.
2. Clarify the behaviour for different types of the “urllib.request” data parameter. I understand “file-like objects” means objects with a “read” attribute, and the “read” method is called in preference to iteration or treating the parameter as a “bytes” object.
Despite the bug title, I don’t think the library should mess with the file position. Certainly not when making a single request. But it should already be possible for the caller to supply a custom iterable object that resets the file position:
class FileReiterator:
def __iter__(self):
self.file.seek(0)
while True:
chunk = self.file.read(self.chunksize)
yield chunk
if len(chunk) < self.chunksize:
break
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue5038>
_______________________________________
More information about the Python-bugs-list
mailing list