classification
Title: urllib.request.urlopen() different on Windows than Linux
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, mark
Priority: normal Keywords:

Created on 2008-09-22 11:18 by mark, last changed 2008-09-22 12:18 by amaury.forgeotdarc. This issue is now closed.

Messages (3)
msg73565 - (view) Author: Mark Summerfield (mark) * Date: 2008-09-22 11:18
Py30rc1

On Windows the file object returned by urllib.request.urlopen() appears
to be in binary mode, so .read() returns a bytes object. But on Linux it
appears to be in text mode, so .read() returns a str object. It seeems
to me that the same type of file object should be returned on all
platforms, otherwise you have to test the platform and use str.encode()
or bytes.decode() depending on where the code is running.
msg73566 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-22 11:36
I only get bytes on Linux. Do you have a test script?
msg73568 - (view) Author: Mark Summerfield (mark) * Date: 2008-09-22 11:59
Sorry, I now can't reproduce it. I made a tiny test script and it worked
fine on both Windows and Linux. Now when I run the real test that works
fine too. So could you close/remove this "bug" for me please?

#!/usr/bin/env python3
import sys
import urllib.request
print(sys.version)
fh = urllib.request.urlopen("http://www.python.org/index.html")
data = fh.read()
fh.close()
print(type(data))

# output when run on Linux:
3.0rc1 (r30rc1:66499, Sep 18 2008, 17:45:22)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)]
<class 'bytes'>

# output when run on Windows:
3.0rc1 (r30rc1:66507, Sep 18 2008, 14:47:08) [MSC v.1500 32 bit (Intel)]
<class 'bytes'>
History
Date User Action Args
2008-09-22 12:18:55amaury.forgeotdarcsetstatus: open -> closed
resolution: not a bug
2008-09-22 11:59:56marksetmessages: + msg73568
2008-09-22 11:36:09amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg73566
2008-09-22 11:18:15markcreate