Problem with character encoding in commandline

Discussion in 'Python' started by gialloporpora, Oct 15, 2009.

  1. Dear all,
    I have a strange problem that I am not able to solve myself.
    I have written a little Python script to download image from last.fm,
    now, if I call it from the python environment it works, if I call it
    from Windows console it doesn't works


    If I open the prompt and run python I call the function:
    (the code is at the end of message)
    >>> lastfm.decodeArgs("é") (e acute è in html)

    I obtain this result:
    %C3%A9
    that is the correct output.

    if I open the windows console (cmd) without enter in Python envinroment,
    and I call script from commandline:

    lastfm.py é

    the result is:
    %C3%9A

    that is not the same and I don't understand the reason.

    If I give the command : chcp from console I have:
    Active code page: 850
    the same code table that I see using the sys.stdin.encoding inside
    Python envinroment.
    Someone know where I make wrong ?

    Thanks
    Sandro

    My code (only the parts that not works)

    ======================
    import sys
    from urllib import quote_plus
    def decodeArgs(s):
    return quote_plus(s.decode(sys.stdin.encoding).encode("utf-8"))
    if __name__ == '__main__':
    args=sys.argv[1]
    print decodeArgs(args)
    ======================



    --
    *gialloporpora: Alex Faaborg - » Browsing Your Personal Web
    http://ff.im/9JDwm * - http://sn.im/shv8b
    *Massimo Bubola - Cuori Ribelli * - http://sn.im/sivjx
    * FAQ* di /it-alt.comp.software.mozilla/: http://bit.ly/1MZ04d
    gialloporpora, Oct 15, 2009
    #1
    1. Advertising

  2. Risposta al messaggio di gialloporpora :

    > Dear all,
    > I have a strange problem that I am not able to solve myself.



    Ok, I have solved my problem, sorry for the post.
    First I had no view this function:
    sys.getfilesystemencoding()

    that return the console encoding, sorry.
    Sandro



    *gialloporpora: Alex Faaborg - » Browsing Your Personal Web
    http://ff.im/9JDwm * - http://sn.im/shv8b
    *Massimo Bubola - Cuori Ribelli * - http://sn.im/sivjx
    * FAQ* di /it-alt.comp.software.mozilla/: http://bit.ly/1MZ04d
    gialloporpora, Oct 15, 2009
    #2
    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. =?Utf-8?B?VGhvbWFzIEthcmxzc29u?=

    Character encoding problem?

    =?Utf-8?B?VGhvbWFzIEthcmxzc29u?=, Feb 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    329
    =?Utf-8?B?VGhvbWFzIEthcmxzc29u?=
    Feb 2, 2004
  2. raavi
    Replies:
    2
    Views:
    901
    raavi
    Mar 2, 2006
  3. Dhananjay
    Replies:
    8
    Views:
    6,994
    Dhananjay
    May 10, 2006
  4. bj
    Replies:
    2
    Views:
    329
    Thomas Fritsch
    Jun 15, 2007
  5. bob
    Replies:
    1
    Views:
    138
    Axel Etzold
    Jun 14, 2007
Loading...

Share This Page