urlretrieve a file whose name has spaces in it

Discussion in 'Python' started by HP, Jul 29, 2003.

  1. HP

    HP Guest

    I am using urllib.urlretrieve() 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.urlretrieve("http://website.com/path/string string1 foo.doc",
    "local_file");

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

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

    thanks
    HP
     
    HP, Jul 29, 2003
    #1
    1. Advertising

  2. HP wrote:
    > urllib.urlretrieve("http://website.com/path/string string1 foo.doc",
    > "local_file");
    >


    Try

    urllib.urlretrieve(urllib.quote("http://website.com/path/string string1 foo.doc"), "local_file")

    instead.

    And what is the semicolon doing there? ;-)

    --Irmen
     
    Irmen de Jong, Jul 29, 2003
    #2
    1. Advertising

  3. You can easily escape spaces with "%20"

    as in:


    urllib.urlretrieve("http://website.com/path/string string1
    foo.doc".replace(" ", "%20"), "local_file")



    (HP) wrote in message news:<>...
    > I am using urllib.urlretrieve() 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.urlretrieve("http://website.com/path/string string1 foo.doc",
    > "local_file");
    >
    > produces local_file which contains the following one line:
    > <html><head><title>Error</title></head><body>The parameter is
    > incorrect. </body></html>
    >
    > What is the correct way of specifying the this file in urlretrieve() ?
    >
    > thanks
    > HP
     
    Kevin Cazabon, Jul 31, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bearclaws
    Replies:
    4
    Views:
    4,706
    bearclaws
    Mar 1, 2005
  2. Sven

    urlretrieve get file name

    Sven, Nov 9, 2006, in forum: Python
    Replies:
    6
    Views:
    500
  3. Harald van Dijk

    Re: whose c compiler has command just "c" ?

    Harald van Dijk, Aug 31, 2011, in forum: C Programming
    Replies:
    3
    Views:
    302
    Rui Maciel
    Sep 3, 2011
  4. Joachim Schmitz

    Re: whose c compiler has command just "c" ?

    Joachim Schmitz, Sep 1, 2011, in forum: C Programming
    Replies:
    1
    Views:
    308
    David Thompson
    Sep 6, 2011
  5. Fourchette Fourchette
    Replies:
    4
    Views:
    173
    Fourchette Fourchette
    Aug 6, 2010
Loading...

Share This Page