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.urlopen("///C|/foo/bar/spam.foo") IOError: [Errno 22]
Type: behavior Stage: test needed
Components: Library (Lib), Windows Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: cgohlke, eric.araujo, orsenthil
Priority: normal Keywords: needs review, patch

Created on 2010-01-21 22:55 by cgohlke, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
url2pathname.patch cgohlke, 2010-01-21 22:55 patch
test_nturl2path.diff cgohlke, 2010-02-16 07:53
Messages (7)
msg98119 - (view) Author: Christoph Gohlke (cgohlke) Date: 2010-01-21 22:55
On Windows 7, Python 2.6 raises an IOError when opening a valid file URL with urllib.urlopen(). A patch to the nturl2path.url2pathname function is attached. It replaces '%7C' by '|' in the url at the top of the url2pathname function.

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, urllib
>>> fname = sys.executable
>>> fname
'x:\\python26\\python.exe'
>>> fname = "file:///" + fname.replace('\\', '/').replace(':', '|')
>>> fname
'file:///x|/python26/python.exe'
>>> urllib.urlopen(fname)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "x:\python26\lib\urllib.py", line 87, in urlopen
    return opener.open(url)
  File "x:\python26\lib\urllib.py", line 206, in open
    return getattr(self, name)(url)
  File "x:\python26\lib\urllib.py", line 468, in open_file
    return self.open_local_file(url)
  File "x:\python26\lib\urllib.py", line 482, in open_local_file
    raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 22] The filename, directory name, or volume label syntax is incorrect: '\\x|\\python26\\python.exe'
msg99386 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-02-16 05:13
Hello

I’m no expert on Python bugs, but I believe a test for the fixed behavior would improve your patch. Maybe a link to some documentation in a comment (or in an entry in Misc/NEWS) too.

Regards
msg99389 - (view) Author: Christoph Gohlke (cgohlke) Date: 2010-02-16 07:53
A testcase is attached.

Information about the file URI scheme can be found at:

http://en.wikipedia.org/wiki/File_URI_scheme
http://tools.ietf.org/html/draft-hoffman-file-uri-03
http://blogs.msdn.com/ie/archive/2006/12/06/file-uris-in-windows.aspx
http://www.cs.tut.fi/~jkorpela/fileurl.html
msg99635 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-02-20 22:07
cgohlke, thanks for the patches and sorry for the delay. The fix however is not to replace the %HH character of '|' with '|', in the nturl2path, but the keep the '|' as safe character in the urllib.urlopen.

-        fullurl = quote(fullurl, safe="%/:=&?~#+!$,;'@()*[]")
+        fullurl = quote(fullurl, safe="%/:=&?~#+!$,;'@()*[]|")

Fixed in the revision 78268 with tests added.
msg99637 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-02-20 23:49
Hello

I’m no Windows expert but from what I know I’m puzzled by the test and the fix that have been committed. I thought the path C:\something would correspond to the URI file:///C|/something. Could you enlighten me?

Regards
msg99641 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-02-21 04:00
The reason the problem was appearing in windows was, it is where, the | is normally observed in URLS, Without | being a safe character, that is it can appear literally in the url, the open method was translating it to %7C. Christopher's patch was to reconvert it to '|' later. 
I thought about it a bit and added '|' to safe characters.
Also, the tests were not very specific to windows, but to test the functionality of the open method leaving the safe characters unquoted.
msg99648 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-02-21 10:35
Ok, thanks for clarifying :)

Regards
History
Date User Action Args
2022-04-11 14:56:56adminsetgithub: 51999
2010-02-21 10:35:51eric.araujosetmessages: + msg99648
2010-02-21 04:00:56orsenthilsetstatus: open -> closed

messages: + msg99641
2010-02-20 23:49:15eric.araujosetmessages: + msg99637
2010-02-20 22:07:27orsenthilsetassignee: orsenthil
resolution: fixed
messages: + msg99635
2010-02-16 07:53:49cgohlkesetfiles: + test_nturl2path.diff

messages: + msg99389
2010-02-16 05:13:13eric.araujosetnosy: + eric.araujo
messages: + msg99386
2010-01-23 14:21:29pitrousetnosy: + orsenthil
2010-01-22 00:16:56brian.curtinsetpriority: normal
keywords: + needs review
type: crash -> behavior
stage: test needed
2010-01-21 22:55:24cgohlkecreate