[Tutor] encode question!

铁石 winglion1 at 163.com
Tue Sep 27 14:19:30 CEST 2005


tutor-request
     Thanks Ziyad.You answer is exactly the realson it is! I am missdirect
by the coding of the html. the %25 in the url is the '%' char in file name.
after  
    urllib.unquote('xvg_h%25202.jpg')
    'xvg_h%202.jpg'
That's the real filename I want!
thanks too, Danny Yoo!

>This has nothing to do with Big5 encoding!  This is how URL are sent in
>HTTP requests.  As an example: a space letter " " become "%20".
>
>In your example above your file name is probably named "xvg_h 2.jpg".
>So, what's going on?  When you viewed the image in you browser (or the
>application you used to download it, even if you were using Python
>scrip) the request was something like:
>        http://server.domain.tld/dir1/dir2/xvg_h%202.jpg
>which translate to "xvg_h 2.jpg" which is right.  However, when you
>saved the HTML file along with the image, the application interpreted
>the "%20" as the character "percent sign" followed by the characters
>"20".  It also encoded them as such (just like when sending HTTP
>requests) and that resulted in "xvg_h%25202.jpg"!
>
>How to fix this?  Use "unquote()" from the "urllib" module twice!
>
>Here:
>        >>> urllib.unquote(urllib.unquote('xvg_h%25202.jpg'))
>        'xvg_h 2.jpg'
>
>I hope this is the right explanation and that it will work for you.  If
>anyone have a better opinion please don't be shy and help us all.
>Ziyad.
>
>

        winglion1 at 163.com
          2005-09-27



More information about the Tutor mailing list