teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

とりあえず原因が分かったので削除しました。

2018/11/26 04:41

投稿

kiwibird
kiwibird

スコア105

title CHANGED
File without changes
body CHANGED
@@ -1,200 +1,3 @@
1
- # **追記その2**
2
-
3
- **gh640**さんが仰っていたコマンドを実行しました!ありがとうございます!
4
- **centOSのPython**と**Djangoのインタラクティブシェル**の実行結果です。
5
-
6
- ## CentOS上のPython3.6.5
7
-
8
- ### CASE **A**
9
-
10
- ```python
11
- >>> import os, sys, json
12
- >>> path = 'media/movies'
13
- >>> result = os.listdir(path)
14
- >>> print(result)
15
- ['テスト1', 'test1.mp4', 'test2.mp4', 'テスト2', 'テスト4', 'テスト3']
16
- >>> print(json.dumps(result, ensure_ascii=False))
17
- ["テスト1", "test1.mp4", "test2.mp4", "テスト2", "テスト4", "テスト3"]
18
- ```
19
-
20
- ### CASE **B**
21
-
22
- ```python
23
- >>> import os, sys, json
24
- >>> result = os.listdir(b'media/movies')
25
- >>> entries = [e.decode(sys.getfilesystemencoding()) for e in result]
26
- >>> print(entries)
27
- ['テスト1', 'test1.mp4', 'test2.mp4', 'テスト2', 'テスト4', 'テスト3']
28
- >>> print(json.dumps(result, ensure_ascii=False))
29
- Traceback (most recent call last):
30
- File "<stdin>", line 1, in <module>
31
- File "/usr/lib64/python3.6/json/__init__.py", line 238, in dumps
32
- **kw).encode(obj)
33
- File "/usr/lib64/python3.6/json/encoder.py", line 199, in encode
34
- chunks = self.iterencode(o, _one_shot=True)
35
- File "/usr/lib64/python3.6/json/encoder.py", line 257, in iterencode
36
- return _iterencode(o, 0)
37
- File "/usr/lib64/python3.6/json/encoder.py", line 180, in default
38
- o.__class__.__name__)
39
- TypeError: Object of type 'bytes' is not JSON serializable
40
- ```
41
-
42
- ## django上のPython(`py manage.py shell`)
43
-
44
- ### CASE **A**
45
-
46
- ```python
47
- >>> import os, sys, json
48
- >>> path = 'media/movies'
49
- >>> result = os.listdir(path)
50
- >>> print(result)
51
- ['テスト1', 'test1.mp4', 'test2.mp4', 'テスト2', 'テスト4', 'テスト3']
52
- >>> print(json.dumps(result, ensure_ascii=False))
53
- ["テスト1", "test1.mp4", "test2.mp4", "テスト2", "テスト4", "テスト3"]
54
- ```
55
-
56
- ### CASE **B**
57
-
58
- ```python
59
- >>> import os, sys, json
60
- >>> result = os.listdir(b'media/movies')
61
- >>> entries = [e.decode(sys.getfilesystemencoding()) for e in result]
62
- >>> print(entries)
63
- ['テスト1', 'test1.mp4', 'test2.mp4', 'テスト2', 'テスト4', 'テスト3']
64
- >>> print(json.dumps(result, ensure_ascii=False))
65
- Traceback (most recent call last):
66
- File "<console>", line 1, in <module>
67
- File "/usr/lib64/python3.6/json/__init__.py", line 238, in dumps
68
- **kw).encode(obj)
69
- File "/usr/lib64/python3.6/json/encoder.py", line 199, in encode
70
- chunks = self.iterencode(o, _one_shot=True)
71
- File "/usr/lib64/python3.6/json/encoder.py", line 257, in iterencode
72
- return _iterencode(o, 0)
73
- File "/usr/lib64/python3.6/json/encoder.py", line 180, in default
74
- o.__class__.__name__)
75
- TypeError: Object of type 'bytes' is not JSON serializable
76
- ```
77
-
78
- 以上になります!通常の`shell`と`django上のshell`にて実行しましたが、**同じ結果**となりました。
79
- ついでに試しにやってみたんですが、`os.listdir('media/movies')`の結果を一つずつ`encode()`してから`deocde()`した結果も貼っておきます。
80
-
81
- ### os上のpython3.6.5
82
-
83
- ```python
84
- >>> import os, sys, json
85
- >>> result = os.listdir('media/movies')
86
- >>> json.dumps([i.encode('utf-8').decode('utf-8') for i in result])
87
- '["\u30c6\u30b9\u30c81", "test1.mp4", "test2.mp4", "\u30c6\u30b9\u30c82", "\u30c6\u30b9\u30c84", "\u30c6\u30b9\u30c83"]'
88
- ```
89
-
90
- ### django(py manage.py shell)
91
-
92
- ```python
93
- >>> import os, sys, json
94
- >>> result = os.listdir('media/movies')
95
- >>> json.dumps([i.encode('utf-8').decode('utf-8') for i in result])
96
- '["\u30c6\u30b9\u30c81", "test1.mp4", "test2.mp4", "\u30c6\u30b9\u30c82", "\u30c6\u30b9\u30c84", "\u30c6\u30b9\u30c83"]'
97
- ```
98
-
99
- ###### シェルだと普通にエンコード出来てるのに、なぜdjnagoだとサロゲートペアが云々...
100
-
101
- # **追記**
102
-
103
- 皆様、親切なご回答有り難うございます!ご指摘の通りにCentOS7の`locale`や`LANG`を確認してみました。
104
- また、localeが対応している文字コードについても記載しておきます。
105
-
106
- ```bash
107
- [kiwi@118-27-32-60 ~/app/archer]$ locale -a | grep ja
108
- ja_JP
109
- ja_JP.eucjp
110
- ja_JP.ujis
111
- ja_JP.utf8
112
- japanese
113
- japanese.euc
114
-
115
- [kiwi@118-27-32-60 ~/app/archer]$ locale -a | grep c.utf8
116
- [kiwi@118-27-32-60 ~/app/archer]$ locale -a | grep en_US.utf8
117
- en_US.utf8
118
- ```
119
-
120
- #### 環境変数 `LANG`
121
-
122
- ```bash
123
- [kiwi@118-27-32-60 ~]$ export | grep LANG
124
- declare -x LANG="ja_JP.utf8"
125
- ```
126
-
127
- #### `locale`コマンド
128
-
129
- ```bash
130
- [kiwi@118-27-32-60 ~]$ locale
131
- LANG=ja_JP.utf8
132
- LC_CTYPE="ja_JP.utf8"
133
- LC_NUMERIC="ja_JP.utf8"
134
- LC_TIME="ja_JP.utf8"
135
- LC_COLLATE="ja_JP.utf8"
136
- LC_MONETARY="ja_JP.utf8"
137
- LC_MESSAGES="ja_JP.utf8"
138
- LC_PAPER="ja_JP.utf8"
139
- LC_NAME="ja_JP.utf8"
140
- LC_ADDRESS="ja_JP.utf8"
141
- LC_TELEPHONE="ja_JP.utf8"
142
- LC_MEASUREMENT="ja_JP.utf8"
143
- LC_IDENTIFICATION="ja_JP.utf8"
144
- LC_ALL=
145
- ```
146
-
147
- となりました。ご指摘の通り、`c.utf8`や`en_US.utf8`に修正して`reboot`してみたりしましたが、サーバーが英語になるだけで相変わらず文字化けしていました...。
148
-
149
- #### `localectl`コマンド
150
-
151
- ```bash
152
- [kiwi@118-27-32-60 ~]$ localectl status
153
- System Locale: LANG=ja_JP.utf8
154
- VC Keymap: jp
155
- X11 Layout: jp
156
- ```
157
-
158
- また、**gh640**さんのご指摘に乗っ取り、`HttpResponse(json.dumps())`でレスポンスしてみましたが、`500`エラーが返ってきます(涙
159
-
160
- ```python
161
- result = os.listdir(path)
162
- return HttpResponse(json.dumps(result, ensure_ascii=False))
163
-
164
- >>>
165
- UnicodeEncodeError at /api/get_list
166
- 'utf-8' codec can't encode characters in position 2-10: surrogates not allowed
167
-
168
- Server time: 驥�, 23 11譛� 2018 19:41:05 +0900
169
-
170
- Exception Type: UnicodeEncodeError at /api/get_list
171
- Exception Value: 'utf-8' codec can't encode characters in position 2-10: surrogates not allowed
172
-
173
- wsgi.errors = <_io.TextIOWrapper name='<wsgi.errors>' encoding='utf-8'>
174
-
175
- Settings:
176
- DEFAULT_CHARSET = 'utf-8'
177
- DEFAULT_CONTENT_TYPE = 'text/html'
178
-
179
- LANGUAGES = [('af', 'Afrikaans'), ('ar', 'Arabic'), ('ast', 'Asturian'), ('az', 'Azerbaijani'), ('bg', 'Bulgarian'), ('be', 'Belarusian'), ('bn', 'Bengali'), ('br', 'Breton'), ('bs', 'Bosnian'), ('ca', 'Catalan'), ('cs', 'Czech'), ('cy', 'Welsh'), ('da', 'Danish'), ('de', 'German'), ('dsb', 'Lower Sorbian'), ('el', 'Greek'), ('en', 'English'), ('en-au', 'Australian English'), ('en-gb', 'British English'), ('eo', 'Esperanto'), ('es', 'Spanish'), ('es-ar', 'Argentinian Spanish'), ('es-co', 'Colombian Spanish'), ('es-mx', 'Mexican Spanish'), ('es-ni', 'Nicaraguan Spanish'), ('es-ve', 'Venezuelan Spanish'), ('et', 'Estonian'), ('eu', 'Basque'), ('fa', 'Persian'), ('fi', 'Finnish'), ('fr', 'French'), ('fy', 'Frisian'), ('ga', 'Irish'), ('gd', 'Scottish Gaelic'), ('gl', 'Galician'), ('he', 'Hebrew'), ('hi', 'Hindi'), ('hr', 'Croatian'), ('hsb', 'Upper Sorbian'), ('hu', 'Hungarian'), ('ia', 'Interlingua'), ('id', 'Indonesian'), ('io', 'Ido'), ('is', 'Icelandic'), ('it', 'Italian'), ('ja', 'Japanese'), ('ka', 'Georgian'), ('kab', 'Kabyle'), ('kk', 'Kazakh'), ('km', 'Khmer'), ('kn', 'Kannada'), ('ko', 'Korean'), ('lb', 'Luxembourgish'), ('lt', 'Lithuanian'), ('lv', 'Latvian'), ('mk', 'Macedonian'), ('ml', 'Malayalam'), ('mn', 'Mongolian'), ('mr', 'Marathi'), ('my', 'Burmese'), ('nb', 'Norwegian Bokmテ・l'), ('ne', 'Nepali'), ('nl', 'Dutch'), ('nn', 'Norwegian Nynorsk'), ('os', 'Ossetic'), ('pa', 'Punjabi'), ('pl', 'Polish'), ('pt', 'Portuguese'), ('pt-br', 'Brazilian Portuguese'), ('ro', 'Romanian'), ('ru', 'Russian'), ('sk', 'Slovak'), ('sl', 'Slovenian'), ('sq', 'Albanian'), ('sr', 'Serbian'), ('sr-latn', 'Serbian Latin'), ('sv', 'Swedish'), ('sw', 'Swahili'), ('ta', 'Tamil'), ('te', 'Telugu'), ('th', 'Thai'), ('tr', 'Turkish'), ('tt', 'Tatar'), ('udm', 'Udmurt'), ('uk', 'Ukrainian'), ('ur', 'Urdu'), ('vi', 'Vietnamese'), ('zh-hans', 'Simplified Chinese'), ('zh-hant', 'Traditional Chinese')]
180
- LANGUAGES_BIDI = ['he', 'ar', 'fa', 'ur']
181
- LANGUAGE_CODE = 'ja'
182
- LANGUAGE_COOKIE_AGE = None
183
- LANGUAGE_COOKIE_DOMAIN = None
184
- LANGUAGE_COOKIE_NAME = 'django_language'
185
- LANGUAGE_COOKIE_PATH = '/'
186
- TIME_ZONE = 'Asia/Tokyo'
187
- USE_I18N = True
188
- USE_L10N = True
189
- USE_THOUSAND_SEPARATOR = False
190
- USE_TZ = True
191
-
192
- ```
193
-
194
- `'utf-8' codec can't encode characters in position 2-10: surrogates not allowed`とあるので、やはりサロゲートペア?の問題なのでしょうか?しかし、ただ`list`を返しているだけなのですが...ファイル名の文字コードがそもそもおかしいのかな、とも思い`nkf`コマンドで変換なども試してみましたが、**既にUTF-8**です...と返されて泣きました。
195
-
196
- ---
197
-
198
1
  ## 概要
199
2
 
200
3
  POSTで指定したディレクトリ内のファイル一覧を返すAPIをDjangoで構築しています。

3

追記その2を追加しました。centosのpythonシェルとdjangoのシェルでCASE A CASE Bをそれぞれ実行しました。

2018/11/26 04:41

投稿

kiwibird
kiwibird

スコア105

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,103 @@
1
+ # **追記その2**
2
+
3
+ **gh640**さんが仰っていたコマンドを実行しました!ありがとうございます!
4
+ **centOSのPython**と**Djangoのインタラクティブシェル**の実行結果です。
5
+
6
+ ## CentOS上のPython3.6.5
7
+
8
+ ### CASE **A**
9
+
10
+ ```python
11
+ >>> import os, sys, json
12
+ >>> path = 'media/movies'
13
+ >>> result = os.listdir(path)
14
+ >>> print(result)
15
+ ['テスト1', 'test1.mp4', 'test2.mp4', 'テスト2', 'テスト4', 'テスト3']
16
+ >>> print(json.dumps(result, ensure_ascii=False))
17
+ ["テスト1", "test1.mp4", "test2.mp4", "テスト2", "テスト4", "テスト3"]
18
+ ```
19
+
20
+ ### CASE **B**
21
+
22
+ ```python
23
+ >>> import os, sys, json
24
+ >>> result = os.listdir(b'media/movies')
25
+ >>> entries = [e.decode(sys.getfilesystemencoding()) for e in result]
26
+ >>> print(entries)
27
+ ['テスト1', 'test1.mp4', 'test2.mp4', 'テスト2', 'テスト4', 'テスト3']
28
+ >>> print(json.dumps(result, ensure_ascii=False))
29
+ Traceback (most recent call last):
30
+ File "<stdin>", line 1, in <module>
31
+ File "/usr/lib64/python3.6/json/__init__.py", line 238, in dumps
32
+ **kw).encode(obj)
33
+ File "/usr/lib64/python3.6/json/encoder.py", line 199, in encode
34
+ chunks = self.iterencode(o, _one_shot=True)
35
+ File "/usr/lib64/python3.6/json/encoder.py", line 257, in iterencode
36
+ return _iterencode(o, 0)
37
+ File "/usr/lib64/python3.6/json/encoder.py", line 180, in default
38
+ o.__class__.__name__)
39
+ TypeError: Object of type 'bytes' is not JSON serializable
40
+ ```
41
+
42
+ ## django上のPython(`py manage.py shell`)
43
+
44
+ ### CASE **A**
45
+
46
+ ```python
47
+ >>> import os, sys, json
48
+ >>> path = 'media/movies'
49
+ >>> result = os.listdir(path)
50
+ >>> print(result)
51
+ ['テスト1', 'test1.mp4', 'test2.mp4', 'テスト2', 'テスト4', 'テスト3']
52
+ >>> print(json.dumps(result, ensure_ascii=False))
53
+ ["テスト1", "test1.mp4", "test2.mp4", "テスト2", "テスト4", "テスト3"]
54
+ ```
55
+
56
+ ### CASE **B**
57
+
58
+ ```python
59
+ >>> import os, sys, json
60
+ >>> result = os.listdir(b'media/movies')
61
+ >>> entries = [e.decode(sys.getfilesystemencoding()) for e in result]
62
+ >>> print(entries)
63
+ ['テスト1', 'test1.mp4', 'test2.mp4', 'テスト2', 'テスト4', 'テスト3']
64
+ >>> print(json.dumps(result, ensure_ascii=False))
65
+ Traceback (most recent call last):
66
+ File "<console>", line 1, in <module>
67
+ File "/usr/lib64/python3.6/json/__init__.py", line 238, in dumps
68
+ **kw).encode(obj)
69
+ File "/usr/lib64/python3.6/json/encoder.py", line 199, in encode
70
+ chunks = self.iterencode(o, _one_shot=True)
71
+ File "/usr/lib64/python3.6/json/encoder.py", line 257, in iterencode
72
+ return _iterencode(o, 0)
73
+ File "/usr/lib64/python3.6/json/encoder.py", line 180, in default
74
+ o.__class__.__name__)
75
+ TypeError: Object of type 'bytes' is not JSON serializable
76
+ ```
77
+
78
+ 以上になります!通常の`shell`と`django上のshell`にて実行しましたが、**同じ結果**となりました。
79
+ ついでに試しにやってみたんですが、`os.listdir('media/movies')`の結果を一つずつ`encode()`してから`deocde()`した結果も貼っておきます。
80
+
81
+ ### os上のpython3.6.5
82
+
83
+ ```python
84
+ >>> import os, sys, json
85
+ >>> result = os.listdir('media/movies')
86
+ >>> json.dumps([i.encode('utf-8').decode('utf-8') for i in result])
87
+ '["\u30c6\u30b9\u30c81", "test1.mp4", "test2.mp4", "\u30c6\u30b9\u30c82", "\u30c6\u30b9\u30c84", "\u30c6\u30b9\u30c83"]'
88
+ ```
89
+
90
+ ### django(py manage.py shell)
91
+
92
+ ```python
93
+ >>> import os, sys, json
94
+ >>> result = os.listdir('media/movies')
95
+ >>> json.dumps([i.encode('utf-8').decode('utf-8') for i in result])
96
+ '["\u30c6\u30b9\u30c81", "test1.mp4", "test2.mp4", "\u30c6\u30b9\u30c82", "\u30c6\u30b9\u30c84", "\u30c6\u30b9\u30c83"]'
97
+ ```
98
+
99
+ ###### シェルだと普通にエンコード出来てるのに、なぜdjnagoだとサロゲートペアが云々...
100
+
1
101
  # **追記**
2
102
 
3
103
  皆様、親切なご回答有り難うございます!ご指摘の通りにCentOS7の`locale`や`LANG`を確認してみました。
@@ -71,14 +171,6 @@
71
171
  Exception Value: 'utf-8' codec can't encode characters in position 2-10: surrogates not allowed
72
172
 
73
173
  wsgi.errors = <_io.TextIOWrapper name='<wsgi.errors>' encoding='utf-8'>
74
- wsgi.file_wrapper = ''
75
- wsgi.input = <mod_wsgi.Input object at 0x7f221e757c70>
76
- wsgi.input_terminated = True
77
- wsgi.multiprocess = True
78
- wsgi.multithread = True
79
- wsgi.run_once = False
80
- wsgi.url_scheme = 'https'
81
- wsgi.version = '(1, 0)'
82
174
 
83
175
  Settings:
84
176
  DEFAULT_CHARSET = 'utf-8'

2

修正漏れの追記

2018/11/23 16:37

投稿

kiwibird
kiwibird

スコア105

title CHANGED
File without changes
body CHANGED
@@ -44,7 +44,7 @@
44
44
  LC_ALL=
45
45
  ```
46
46
 
47
- となりました。ご指摘の通り、`C.utf8`や`en_US.utf8`
47
+ となりました。ご指摘の通り、`c.utf8`や`en_US.utf8`に修正して`reboot`してみたりしましたが、サーバーが英語になるだけで相変わらず文字化けしていました...。
48
48
 
49
49
  #### `localectl`コマンド
50
50
 

1

サーバー側の文字コードについての追記、追加で試したことを記載

2018/11/23 10:54

投稿

kiwibird
kiwibird

スコア105

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,110 @@
1
+ # **追記**
2
+
3
+ 皆様、親切なご回答有り難うございます!ご指摘の通りにCentOS7の`locale`や`LANG`を確認してみました。
4
+ また、localeが対応している文字コードについても記載しておきます。
5
+
6
+ ```bash
7
+ [kiwi@118-27-32-60 ~/app/archer]$ locale -a | grep ja
8
+ ja_JP
9
+ ja_JP.eucjp
10
+ ja_JP.ujis
11
+ ja_JP.utf8
12
+ japanese
13
+ japanese.euc
14
+
15
+ [kiwi@118-27-32-60 ~/app/archer]$ locale -a | grep c.utf8
16
+ [kiwi@118-27-32-60 ~/app/archer]$ locale -a | grep en_US.utf8
17
+ en_US.utf8
18
+ ```
19
+
20
+ #### 環境変数 `LANG`
21
+
22
+ ```bash
23
+ [kiwi@118-27-32-60 ~]$ export | grep LANG
24
+ declare -x LANG="ja_JP.utf8"
25
+ ```
26
+
27
+ #### `locale`コマンド
28
+
29
+ ```bash
30
+ [kiwi@118-27-32-60 ~]$ locale
31
+ LANG=ja_JP.utf8
32
+ LC_CTYPE="ja_JP.utf8"
33
+ LC_NUMERIC="ja_JP.utf8"
34
+ LC_TIME="ja_JP.utf8"
35
+ LC_COLLATE="ja_JP.utf8"
36
+ LC_MONETARY="ja_JP.utf8"
37
+ LC_MESSAGES="ja_JP.utf8"
38
+ LC_PAPER="ja_JP.utf8"
39
+ LC_NAME="ja_JP.utf8"
40
+ LC_ADDRESS="ja_JP.utf8"
41
+ LC_TELEPHONE="ja_JP.utf8"
42
+ LC_MEASUREMENT="ja_JP.utf8"
43
+ LC_IDENTIFICATION="ja_JP.utf8"
44
+ LC_ALL=
45
+ ```
46
+
47
+ となりました。ご指摘の通り、`C.utf8`や`en_US.utf8`
48
+
49
+ #### `localectl`コマンド
50
+
51
+ ```bash
52
+ [kiwi@118-27-32-60 ~]$ localectl status
53
+ System Locale: LANG=ja_JP.utf8
54
+ VC Keymap: jp
55
+ X11 Layout: jp
56
+ ```
57
+
58
+ また、**gh640**さんのご指摘に乗っ取り、`HttpResponse(json.dumps())`でレスポンスしてみましたが、`500`エラーが返ってきます(涙
59
+
60
+ ```python
61
+ result = os.listdir(path)
62
+ return HttpResponse(json.dumps(result, ensure_ascii=False))
63
+
64
+ >>>
65
+ UnicodeEncodeError at /api/get_list
66
+ 'utf-8' codec can't encode characters in position 2-10: surrogates not allowed
67
+
68
+ Server time: 驥�, 23 11譛� 2018 19:41:05 +0900
69
+
70
+ Exception Type: UnicodeEncodeError at /api/get_list
71
+ Exception Value: 'utf-8' codec can't encode characters in position 2-10: surrogates not allowed
72
+
73
+ wsgi.errors = <_io.TextIOWrapper name='<wsgi.errors>' encoding='utf-8'>
74
+ wsgi.file_wrapper = ''
75
+ wsgi.input = <mod_wsgi.Input object at 0x7f221e757c70>
76
+ wsgi.input_terminated = True
77
+ wsgi.multiprocess = True
78
+ wsgi.multithread = True
79
+ wsgi.run_once = False
80
+ wsgi.url_scheme = 'https'
81
+ wsgi.version = '(1, 0)'
82
+
83
+ Settings:
84
+ DEFAULT_CHARSET = 'utf-8'
85
+ DEFAULT_CONTENT_TYPE = 'text/html'
86
+
87
+ LANGUAGES = [('af', 'Afrikaans'), ('ar', 'Arabic'), ('ast', 'Asturian'), ('az', 'Azerbaijani'), ('bg', 'Bulgarian'), ('be', 'Belarusian'), ('bn', 'Bengali'), ('br', 'Breton'), ('bs', 'Bosnian'), ('ca', 'Catalan'), ('cs', 'Czech'), ('cy', 'Welsh'), ('da', 'Danish'), ('de', 'German'), ('dsb', 'Lower Sorbian'), ('el', 'Greek'), ('en', 'English'), ('en-au', 'Australian English'), ('en-gb', 'British English'), ('eo', 'Esperanto'), ('es', 'Spanish'), ('es-ar', 'Argentinian Spanish'), ('es-co', 'Colombian Spanish'), ('es-mx', 'Mexican Spanish'), ('es-ni', 'Nicaraguan Spanish'), ('es-ve', 'Venezuelan Spanish'), ('et', 'Estonian'), ('eu', 'Basque'), ('fa', 'Persian'), ('fi', 'Finnish'), ('fr', 'French'), ('fy', 'Frisian'), ('ga', 'Irish'), ('gd', 'Scottish Gaelic'), ('gl', 'Galician'), ('he', 'Hebrew'), ('hi', 'Hindi'), ('hr', 'Croatian'), ('hsb', 'Upper Sorbian'), ('hu', 'Hungarian'), ('ia', 'Interlingua'), ('id', 'Indonesian'), ('io', 'Ido'), ('is', 'Icelandic'), ('it', 'Italian'), ('ja', 'Japanese'), ('ka', 'Georgian'), ('kab', 'Kabyle'), ('kk', 'Kazakh'), ('km', 'Khmer'), ('kn', 'Kannada'), ('ko', 'Korean'), ('lb', 'Luxembourgish'), ('lt', 'Lithuanian'), ('lv', 'Latvian'), ('mk', 'Macedonian'), ('ml', 'Malayalam'), ('mn', 'Mongolian'), ('mr', 'Marathi'), ('my', 'Burmese'), ('nb', 'Norwegian Bokmテ・l'), ('ne', 'Nepali'), ('nl', 'Dutch'), ('nn', 'Norwegian Nynorsk'), ('os', 'Ossetic'), ('pa', 'Punjabi'), ('pl', 'Polish'), ('pt', 'Portuguese'), ('pt-br', 'Brazilian Portuguese'), ('ro', 'Romanian'), ('ru', 'Russian'), ('sk', 'Slovak'), ('sl', 'Slovenian'), ('sq', 'Albanian'), ('sr', 'Serbian'), ('sr-latn', 'Serbian Latin'), ('sv', 'Swedish'), ('sw', 'Swahili'), ('ta', 'Tamil'), ('te', 'Telugu'), ('th', 'Thai'), ('tr', 'Turkish'), ('tt', 'Tatar'), ('udm', 'Udmurt'), ('uk', 'Ukrainian'), ('ur', 'Urdu'), ('vi', 'Vietnamese'), ('zh-hans', 'Simplified Chinese'), ('zh-hant', 'Traditional Chinese')]
88
+ LANGUAGES_BIDI = ['he', 'ar', 'fa', 'ur']
89
+ LANGUAGE_CODE = 'ja'
90
+ LANGUAGE_COOKIE_AGE = None
91
+ LANGUAGE_COOKIE_DOMAIN = None
92
+ LANGUAGE_COOKIE_NAME = 'django_language'
93
+ LANGUAGE_COOKIE_PATH = '/'
94
+ TIME_ZONE = 'Asia/Tokyo'
95
+ USE_I18N = True
96
+ USE_L10N = True
97
+ USE_THOUSAND_SEPARATOR = False
98
+ USE_TZ = True
99
+
100
+ ```
101
+
102
+ `'utf-8' codec can't encode characters in position 2-10: surrogates not allowed`とあるので、やはりサロゲートペア?の問題なのでしょうか?しかし、ただ`list`を返しているだけなのですが...ファイル名の文字コードがそもそもおかしいのかな、とも思い`nkf`コマンドで変換なども試してみましたが、**既にUTF-8**です...と返されて泣きました。
103
+
104
+ ---
105
+
106
+ ## 概要
107
+
1
108
  POSTで指定したディレクトリ内のファイル一覧を返すAPIをDjangoで構築しています。
2
109
  どうも、日本語を含むとファイル名が全て文字化けしてしまうようです。
3
110