By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,898 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,898 IT Pros & Developers. It's quick & easy.

Bug in urllib?

P: n/a
urllib.url2pathname("http://127.0.0.1:1030/js.cgi?pca&r=12181")
gives IOError : Bad Url, only coz of the :1030 which should be
accurate portnumber. Is it something I did wrong, or a bug. And what
to do to avoid this (except rewriting url2pathname)?

TIA
Dolf

Oct 14 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
goyatlah wrote:
urllib.url2pathname("http://127.0.0.1:1030/js.cgi?pca&r=12181")
gives IOError : Bad Url, only coz of the :1030 which should be
accurate portnumber. Is it something I did wrong, or a bug. And what
to do to avoid this (except rewriting url2pathname)?
>>help(urllib.url2pathname)
url2pathname(url)
OS-specific conversion from a relative URL of the 'file' scheme
to a file system path; not recommended for general use.

So first, you must use a URL of the 'file' scheme, not of the 'http'
scheme. This is something like:

'file://localhost/C|/srv/cgi.bin/js.cgi' or 'file:///C|/srv/cgi.bin/js.cgi

Second, it must be a "relative URL" which is a bit mistakable here. What
is actually meant is that you must not prepend it with 'file:'.

So you have to pass

'//localhost/C|/srv/cgi.bin/js.cgi' or
'///C|/srv/cgi.bin/js.cgi'

On Windows, this will give you:
>>urllib.url2pathname('//localhost/C|/srv/cgi.bin/js.cgi')
C:\srv\cgi.bin\js.cgi

The docs at http://docs.python.org/lib/module-urllib.html say basically
the same, you need to pass the *path component* of an URL, not the
complete URL.

-- Christoph
Oct 15 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.