In ValueError: unknown url type in urllib2, though the url is fine if opened in a browser, it was pointed out that before calling opener.open() you must ensure that the url passed to it is well-formed (ie – has a “http://” prefix for HTTP urls, “ftp://” for FTP, etc).
The question was refined to ask “Is it possible to handle such cases automatically with some builtin function or I have to do error handling with subsequent string concatenation?” Or put another way: is there a Python built-in for doing this?
However, this refined question was never answered, hence the re-asking here. It’s easy enough to do myself, but why reinvent the wheel right?
In Python it’s quite common to accept and exception instead of checkin the value in advance. So something like this would be perfectly of for me and probably for most python programmers:
But I don’t see how you would like to handle urls without prefix automatically. The prefix defines the protocol to be used. If it’s not given, how would you “guess” it?