Issue 1097834: urllib2 doesn't handle urls without a scheme (original) (raw)
Unlike urllib, urllib2 does not handle "/path/to/file" style urls (without a scheme) as "file:" urls.
I'm not sure whether this is a bug per se, but if this behaviour is by design then urllib2 should get a pathname2url() method that changes a pathname to a "file:"-prefixed url. urllib.pathname2url() does not prefix the url, but that's fine because urllib.urlopen() treats urls without schemes as file: urls.
Logged In: YES user_id=3066
There's no such thing as a URL without a scheme, regardless of what browsers do. The best thing to do is to determine the "base" to which a relative URL reference (whcih can have the scheme omitted) should be resolved, and join the base and relative URL reference using urlparse.urljoin(base, rel).
Closing as "not a bug".
urllib.pathname2url() is a problem in it's own right; it doesn't behave consistently across Windows and Unix. On Windows, pathname2url() returns too many slashes, or it returns too few on Unix. I've been using helper functions that hide that difference.