質問編集履歴

2

エンコード仕様について追記

2018/05/01 05:28

投稿

020n
020n

スコア36

test CHANGED
File without changes
test CHANGED
@@ -47,3 +47,37 @@
47
47
  print(s)
48
48
 
49
49
  ```
50
+
51
+
52
+
53
+ が、そもそも以下関数を利用し、自分でエンコードしていました。。。
54
+
55
+ (sampleスクリプトを流用し、APIのエンドポイントのみ変更していたため、気づきませんでした)
56
+
57
+
58
+
59
+ ```python
60
+
61
+ def _encode_for_display(text):
62
+
63
+ """
64
+
65
+ Encodes strings so they can display as ASCII in a Windows terminal window.
66
+
67
+ This function also encodes strings for processing by xml.etree.ElementTree functions.
68
+
69
+
70
+
71
+ Returns an ASCII-encoded version of the text.
72
+
73
+ Unicode characters are converted to ASCII placeholders (for example, "?").
74
+
75
+ """
76
+
77
+ return text.encode('ascii', errors="backslashreplace").decode('utf-8')
78
+
79
+ ```
80
+
81
+
82
+
83
+ 皆様ご回答ありがとうございました。

1

解決方法記載しました

2018/05/01 05:28

投稿

020n
020n

スコア36

test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,35 @@
15
15
 
16
16
 
17
17
  宜しくお願い致します。
18
+
19
+
20
+
21
+
22
+
23
+ おかげさまで以下コードにてやりたいこと出来ました!
24
+
25
+
26
+
27
+ ```python
28
+
29
+ i, s, name = 0, '', <APIから返ってきた文字列>
30
+
31
+ while i < len(name):
32
+
33
+ if name[i] == '\':
34
+
35
+ s += chr(int(name[i+2:i+6], 16))
36
+
37
+ i+=5
38
+
39
+ else:
40
+
41
+ s += name[i]
42
+
43
+
44
+
45
+ i += 1
46
+
47
+ print(s)
48
+
49
+ ```