urlretrieve a file whose name has spaces in it

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HP

    urlretrieve a file whose name has spaces in it

    I am using urllib.urlretri eve() to download a file from a web site.
    THe trouble is that the file name has spaces in it,
    such as "string string1 foo.doc".

    The statement:
    urllib.urlretri eve("http://website.com/path/string string1 foo.doc",
    "local_file ");

    produces local_file which contains the following one line:
    <html><head><ti tle>Error</title></head><body>The parameter is
    incorrect. </body></html>

    What is the correct way of specifying the this file in urlretrieve() ?

    thanks
    HP
  • Irmen de Jong

    #2
    Re: urlretrieve a file whose name has spaces in it

    HP wrote:[color=blue]
    > urllib.urlretri eve("http://website.com/path/string string1 foo.doc",
    > "local_file ");
    >[/color]

    Try

    urllib.urlretri eve(urllib.quot e("http://website.com/path/string string1 foo.doc"), "local_file ")

    instead.

    And what is the semicolon doing there? ;-)

    --Irmen

    Comment

    • Kevin Cazabon

      #3
      Re: urlretrieve a file whose name has spaces in it

      You can easily escape spaces with "%20"

      as in:


      urllib.urlretri eve("http://website.com/path/string string1
      foo.doc".replac e(" ", "%20"), "local_file ")



      [email protected] (HP) wrote in message news:<10caf2e2. 0307291439.33d9 [email protected] ogle.com>...[color=blue]
      > I am using urllib.urlretri eve() to download a file from a web site.
      > THe trouble is that the file name has spaces in it,
      > such as "string string1 foo.doc".
      >
      > The statement:
      > urllib.urlretri eve("http://website.com/path/string string1 foo.doc",
      > "local_file ");
      >
      > produces local_file which contains the following one line:
      > <html><head><ti tle>Error</title></head><body>The parameter is
      > incorrect. </body></html>
      >
      > What is the correct way of specifying the this file in urlretrieve() ?
      >
      > thanks
      > HP[/color]

      Comment

      Working...