Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

s3cmd で日本語ファイルを ダウンロード、アップロードしたい

More than 5 years have passed since last update.

s3cmd で 日本語が含まれるディレクトリ、ファイルをアップロード、ダウンロードしようとすると、

↓のようなエラーがでます。

[root@localhost ~]# s3cmd --config=/s3cmd/.s3cfg get s3://meister-staging-webroot-published/Account/1/footer_image2/フッタ.gif /tmp/

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    An unexpected error has occurred.
  Please report the following lines to:
   s3tools-bugs@lists.sourceforge.net
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Problem: UnicodeEncodeError: 'ascii' codec can't encode characters in position 63-65: ordinal not in range(128)
S3cmd:   1.0.0

Traceback (most recent call last):
  File "/usr/bin/s3cmd", line 2006, in <module>
    main()
  File "/usr/bin/s3cmd", line 1950, in main
    cmd_func(args)
  File "/usr/bin/s3cmd", line 439, in cmd_object_get
    remote_list = fetch_remote_list(args, require_attribs = False)
  File "/usr/bin/s3cmd", line 281, in fetch_remote_list
    uri_str = str(uri)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 63-65: ordinal not in range(128)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    An unexpected error has occurred.
    Please report the above lines to:
   s3tools-bugs@lists.sourceforge.net
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

これは、

  • s3cmd → Pythonで書かれている
  • Pythonのデフォルトエンコーディング → ASCII

というのが原因の模様。

なので以下のような作業を行い、UTF-8 を扱えるようにすれば、日本語のファイルを扱うことができます。

[root@localhost ~]# cp -ra /usr/bin/s3cmd /usr/bin/s3cmd.orig
[root@localhost ~]# vim /usr/bin/s3cmd
#!/usr/bin/python

## Amazon S3 manager
## Author: Michal Ludvig <michal@logix.cz>
##         http://www.logix.cz/michal
## License: GPL Version 2

import sys
reload(sys)
sys.setdefaultencoding("UTF-8")
[root@localhost ~]# diff /usr/bin/s3cmd /usr/bin/s3cmd.orig
9,10d8
< reload(sys)
< sys.setdefaultencoding("UTF-8")
fusic
個性をかき集めて、驚きの角度から世の中をアップデートしつづける。
https://fusic.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away