私は最近、いくつかのアプリケーションで使用している PyCURL に裏打ちされたアップロード ダイアログを設計しました。
pycurl の HTTPPOST オプションを設定するときに問題が発生しました。次のように設定しています:
self.curl.setopt(self.curl.HTTPPOST, [(field, (self.curl.FORM_FILE, filename))])
filename が文字列の場合、すべて問題ありません。ただし、Unicode を渡すと、TypeError が発生します。キリル文字のパスを与える方法はありますか? UTF-8でエンコードしてみましたがだめでした。お時間をいただきありがとうございます
アップデート:
私は実際に WX コントロールからファイル名を取得しているので、触れる前に Unicode になっています。次に、それを UTF-8 にエンコードすると (filename = filename.encode('UTF-8') を使用)、setopt は正常に動作しますが、実行時にすべてが失敗します。
* About to connect() to example.com port 80 (#0)
* Trying 123.123.123.123... * connected
* Connected to example.com (123.123.123.123) port 80 (#0)
* failed creating formpost data
* Connection #0 to host example.com left intact
Traceback (most recent call last):
File "c:\python27\lib\site-packages\transfer_dialogs-0.28-py2.7.egg\transfer_dialogs\transfer_dialogs.py", line 64, in perform_transfer
self.curl.perform()
error: (26, 'failed creating formpost data')
更新 2:
リクエストに応じて、もう少しデータを。filename には、開いているダイアログからの GetValue() の結果が含まれます。
logging.debug("ファイル名: %r エンコードされたファイル名: %r" % (ファイル名, filename.encode('UTF-8')))
結果:
2011 年 2 月 5 日土曜日 03:33:56 core.dialogs.upload_audio DEBUG:ファイル名: u'C:\Users\Q\test\\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043f\u0430\u043f\u043a\u0430\test.mp3' エンコードされたファイル名: 'C: \Users\Q\test\\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x8f\xd0\xbf\xd0\xb0\xd0\ xbf\xd0\xba\xd0\xb0\test.mp3'