curl-and-python
Re: Uploading files with UTF-8 names
From: Andre Polykanine <andre_at_oire.org>
Date: Mon, 10 Jun 2013 19:21:52 +0300
Date: Mon, 10 Jun 2013 19:21:52 +0300
Hello Zdenek,
local_filename = filename.encode("utf8")
Result:
logging.debug("Local filename is %s: %s" % (local_filename, os.stat(local_filename)))
WindowsError: [Error 2] The system cannot find the file specified: 'D:\\playlists\\Collection\\Main\\M\xc3\xa0nran - Oran na Cloiche.mp3'
local_filename = filename.encode("cp1251")
UnicodeEncodeError: 'charmap' codec can't encode character u'\xe0' in position 30: character maps to <undefined>
-- With best regards from Ukraine, Andre Skype: Francophile My blog: http://oire.org/menelion (mostly in Russian) Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com/menelion ------------ Original message ------------ From: Zdenek Pavlas <zpavlas_at_redhat.com> To: curl with python Date created: , 2:50:45 PM Subject: Uploading files with UTF-8 names > os.stat() here doesn't work either, it says "System cannot find file > specified", because it turns unicode chars into \xe0, \xa9 etc. in the > path. just use the encoded string, not unicode. >> I'd try os.stat() for both encodings in turn, then send to pycurl ^^^^^^^^^^^^^^^^^^ for e in 'cp1251', 'utf8': try: enc = filename.encode(e); os.stat(enc); break except: continue else: raise ... print 'using encoding', e ... curl(enc) _______________________________________________ http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python _______________________________________________ http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-pythonReceived on 2013-06-10