urllib question

Hans F. Updyke hansup at prolynx.com
Fri Jul 7 14:25:34 EDT 2000


paul at fizzylab.com wrote in message <394B196F.5ED9E73 at fizzylab.com>...
>Why does the first example work, but not the second (actual
>URL not supplied, but you get the idea)?

[snip]

>u = urllib.urlopen(string.join(["http://cnn.com/",
>"index.html"]))
>print u.read()

O.K. I'm also new at Python, but I think I see a problem.  Try this:
>>> sample = string.join(["http://cnn.com/","index.html"])
>>> print sample
You should see that the two list members have been joined with a space in
between.  I suspect the web server only responded to the first part of your
expected URL.  You probably got the results you wanted by accident ---
"index.html" used as default response when no page name submitted in URL
request.  In other words, you would see the same output even if you used a
different valid page name.

You can avoid the included space by specifying an empty string as the
delimiter in the string.join method.  In my example, it would look like
this:
>>> sample = string.join(["http://cnn.com/","index.html"], "")

I'm not sure if this approach will fix your
"montstrousQueryString?withParameters" example.  AFAIK, there could be other
lingering problems I'm not smart enough to spot.

Also-learning-this-stuff-ly y'rs
HansUp






More information about the Python-list mailing list