This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib: ... IOError: ... unknown url type: 'c'
Type: behavior Stage:
Components: Library (Lib), Windows Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, r.david.murray, srid
Priority: normal Keywords:

Created on 2009-06-04 19:05 by srid, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg88894 - (view) Author: Sridhar Ratnakumar (srid) Date: 2009-06-04 19:05
On Windows, urllib fails to open local files:

> python -c "import urllib; urllib.urlopen(r'C:\test.txt').read()"
Traceback (most recent call last):
  File "C:\HOME\as\pypm\bin\python-script.py", line 33, in <module>
    exec _val
  File "<string>", line 1, in <module>
  File "C:\Python26\lib\urllib.py", line 87, in urlopen
    return opener.open(url)
  File "C:\Python26\lib\urllib.py", line 200, in open
    return self.open_unknown(fullurl, data)
  File "C:\Python26\lib\urllib.py", line 212, in open_unknown
    raise IOError, ('url error', 'unknown url type', type)
IOError: [Errno url error] unknown url type: 'c'


However, on Unix this is not an issue:

$ python -c "import urllib; print urllib.urlopen('/tmp/test.txt').read()"
Foo
$
msg88895 - (view) Author: Sridhar Ratnakumar (srid) Date: 2009-06-04 19:07
This also happens on 3.1 (urllib.urlrequest) .. and I believe must also
happen on 2.7 and 3.0.
msg88896 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-06-04 19:08
You should use file:// to open local files with urllib.
msg88897 - (view) Author: Sridhar Ratnakumar (srid) Date: 2009-06-04 19:09
Relevant discussion:

http://osdir.com/ml/python.py2exe/2008-03/msg00013.html

[quote]'The only thing I could think of was editing urllib.py and
changing the splittype method (...)'[endquote]
msg88898 - (view) Author: Sridhar Ratnakumar (srid) Date: 2009-06-04 19:10
[Brandl] You should use file:// to open local files with urllib.

Hmm, that is strange. How come it works on Unix without file://?
msg88900 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-06-04 19:33
Because in unix the filename starts with a '/', while in windows your
filename started with a 'C:'.  That looks like the urltype portion of a
url, and it isn't a valid one, so urllib correctly rejects it.
History
Date User Action Args
2022-04-11 14:56:49adminsetgithub: 50443
2009-06-04 19:33:35r.david.murraysetnosy: + r.david.murray
messages: + msg88900
2009-06-04 19:10:23sridsetmessages: + msg88898
2009-06-04 19:09:45sridsetmessages: + msg88897
2009-06-04 19:08:55georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg88896

resolution: wont fix
2009-06-04 19:07:40sridsetmessages: + msg88895
components: + Windows
versions: + Python 3.0, Python 3.1, Python 2.7
2009-06-04 19:05:27sridcreate