回答編集履歴

1

修正

2020/09/23 03:26

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -16,12 +16,26 @@
16
16
 
17
17
  x = b"blue"
18
18
 
19
- print(x)
19
+ print(x, type(x)) # b'blue' <class 'bytes'>
20
20
 
21
21
 
22
22
 
23
23
  y = x.decode("utf-8")
24
24
 
25
- print(y)
25
+ print(y, type(y)) # blue <class 'str'>
26
26
 
27
27
  ```
28
+
29
+
30
+
31
+ 質問の例だと以下のようにすれば str 型になると思います。
32
+
33
+
34
+
35
+ ```diff
36
+
37
+ - str(message.payload)
38
+
39
+ + message.payload.decode("utf-8")
40
+
41
+ ```