0
我有一個可變message
是類型dict
處理蟒字典
>>> print(message)
{TopicPartition(topic='testing_topic', partition=1): [ConsumerRecord(topic='testing_topic', partition=1, offset=0, timestamp=1499411365748, timestamp_type=0, key=None, value=b'{"url":"http://review.travel.rakuten.co.jp/hotel/voice/158886/", "meta":{"url_cnt":"1185","hotelid":"158886","job_id":"0f3de6d4-34bf-4a1a-a803-5640e8d25932"}}', checksum=-309359221, serialized_key_size=-1, serialized_value_size=158)]}
如何從它取回value
部分。 我嘗試了很多,但我無法做到。請建議。
我想要這個。
value=b'{"url":"http://review.travel.rakuten.co.jp/hotel/voice/158886/", "meta":{"url_cnt":"1185","hotelid":"158886","job_id":"0f3de6d4-34bf-4a1a-a803-5640e8d25932"}}'
你嘗試'消息[0] [ '值']'?看起來這些值包含在一個列表中。 –
我得到關鍵錯誤'print(message [0] ['value'])'KeyError:0 – Avi
不知道這些'TopicPartition'和'ConsumerRecord'類是什麼,這很難說。但是你可以嘗試'next(iter(message.values()))[0] .value'。 –