Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
Closed as not planned
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
A value of the Content-length header returned by urllib.request.FileHandler.open_local_file may mismatch the length of data on Linux.
This happens when a file from a special file system (e.g., procfs or sysfs) is requested.
open_local_file relies on st_size; st_size is equal to zero for pseudo files on Linux.
Lines 1506 to 1511 in 8a0d9a6
| size=stats.st_size | |
| modified=email.utils.formatdate(stats.st_mtime, usegmt=True) | |
| mtype=mimetypes.guess_type(filename)[0] | |
| headers=email.message_from_string( | |
| 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n'% | |
| (mtypeor'text/plain', size, modified)) |
Example
>>>importurllib.request>>>url="file:///proc/cpuinfo">>>handler=urllib.request.FileHandler() >>>response=handler.file_open(urllib.request.Request(url)) >>>data=response.read() >>>headers=response.info() >>>assertint(headers["Content-length"]) ==len(data) Traceback (mostrecentcalllast): File"<stdin>", line1, in<module>AssertionError>>>print(headers["Content-length"]) 0>>>print(len(data)) 18294Your environment
- CPython versions tested on: 3.12.0 alpha 0
- Operating system and architecture: Linux
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error