You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
POSTing a large file that I have extracted from a tarfile. I expect that requests should be able to determine the length of that file, set the Content-Length header, and upload it efficiently.
Actual Result
requests fails to determine the file length, goes with Transfer-Encoding: chunked, and the upload is much slower than desired.
Reproduction Steps
Start with a small tarfile, say
echo foo > file1
tar cf tarfile.tar file1
Then use requests.utils.super_len to try and get the length of file1 in the tarfile:
#!/usr/bin/env pythonimporttarfileimportrequeststar=tarfile.open("tarfile.tar")
member=tar.extractfile("file1")
print(f"super_length of member is {requests.utils.super_len(member)}")
result:
Traceback (most recent call last):
File "./demo.py", line 7, in <module>
print(f"super_length of member is {requests.utils.super_len(member)}")
File "/data/developer/.virtualenvs/req-tar/lib/python3.6/site-packages/requests/utils.py", line 119, in super_len
fileno = o.fileno()
AttributeError: '_FileInFile' object has no attribute 'fileno'
The behavior of the member is quite strange here: hasattr(member, fileno) is true, but trying to call member.fileno() results in an AttributeError.
I expect that a sensible fix might be for this exception to catch a broader range of errors.
One can get the length of the member by seeking, so I expect that super_len() should then succeed.
Expected Result
POSTing a large file that I have extracted from a tarfile. I expect that
requests
should be able to determine the length of that file, set theContent-Length
header, and upload it efficiently.Actual Result
requests
fails to determine the file length, goes withTransfer-Encoding: chunked
, and the upload is much slower than desired.Reproduction Steps
Start with a small tarfile, say
Then use
requests.utils.super_len
to try and get the length offile1
in the tarfile:result:
The behavior of the member is quite strange here:
hasattr(member, fileno)
is true, but trying to callmember.fileno()
results in anAttributeError
.I expect that a sensible fix might be for this exception to catch a broader range of errors.
One can get the length of the member by seeking, so I expect that
super_len()
should then succeed.System Information
The text was updated successfully, but these errors were encountered: