I am getting data from Twitter in json format using python but I am getting an error: SyntaxError: unexpected character after line continuation character. How can I solve this?

from kafka import KafkaConsumer
import json
import happybase
import datetime;
import ast

connection = happybase.Connection(host='localhost',port=9090)
table = connection.table('twitter:movietwitter')
consumer=KafkaConsumer('twittertopic',bootstrap_servers='localhost:9092', 
value_deserializer=lambda m: json.dumps(m.encode('ascii')))

feedDetails={}
dict={}
for msg in consumer:
  string = msg.value
  print (string)
  string = string[1:-1]
  #print string
  key=datetime.datetime.now()
  key=str(key)
  key=key.replace("-","").replace(":","").replace(".","").replace(" ","").replace("'", "\"")
  s="{u\'"+key+"\': "+str(string)+"}"
  dict=ast.literal_eval(s)
  print type(dict)

msg.print:-

"{u'quote_count': 0, u'quoted_status_permalink': {u'url': u'/mhZ3FzdyPc.com', u'expanded': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800', u'display': u'twitter.com/thatstarwarsgr\\u2026'}, u'contributors': None, u'truncated': False, u'text': u'RT @wondrousIights: imagine thinking 13 million local ig likes is better than ONE BILLION DOLLARS at the worldwide box office cant relate h\\u2026', u'is_quote_status': True, u'in_reply_to_status_id': None, u'reply_count': 0, u'id': 1122763172023361537, u'favorite_count': 0, u'entities': {u'user_mentions': [{u'id': 764360805156466689, u'indices': [3, 18], u'id_str': u'764360805156466689', u'screen_name': u'wondrousIights', u'name': u'\\U0001d42d\\U0001d422\\U0001d41f\\U0001d41f\\u2661 | \\U0001d7cf\\U0001d7d0'}], u'symbols': [], u'hashtags': [], u'urls': []}, u'quoted_status_id': 1122234629702860800, u'retweeted': False, u'coordinates': None, u'timestamp_ms': u'1556522574798', u'quoted_status': {u'quote_count': 161, u'contributors': None, u'truncated': False, u'text': u'That moment when Kylie Jenner is a better Captain Marvel then the actual Captain Marvel... #captainmarvel /F1GSIW7fpY.com', u'is_quote_status': False, u'in_reply_to_status_id': None, u'reply_count': 128, u'id': 1122234629702860800, u'favorite_count': 434, u'entities': {u'user_mentions': [], u'symbols': [], u'hashtags': [{u'indices': [91, 105], u'text': u'captainmarvel'}], u'urls': [], u'media': [{u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg', u'id_str': u'1122234623407190016', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 462}, u'large': {u'h': 1829, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 815}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623407190016, u'media_url': u'http://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg'}]}, u'retweeted': False, u'coordinates': None, u'source': u'<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>', u'in_reply_to_screen_name': None, u'id_str': u'1122234629702860800', u'display_text_range': [0, 105], u'retweet_count': 68, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': None, u'profile_use_background_image': True, u'default_profile_image': False, u'id': 957651645302624256, u'default_profile': True, u'verified': False, u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/1061031720286224384/-E24rXom_normal.jpg', u'profile_sidebar_fill_color': u'DDEEF6', u'profile_text_color': u'333333', u'followers_count': 7773, u'profile_sidebar_border_color': u'C0DEED', u'id_str': u'957651645302624256', u'profile_background_color': u'F5F8FA', u'listed_count': 36, u'profile_background_image_url_https': u'', u'utc_offset': None, u'statuses_count': 1733, u'description': u'Artist&Youtuber', u'friends_count': 181, u'location': u'California, USA', u'profile_link_color': u'1DA1F2', u'profile_image_url': u'http://pbs.twimg.com/profile_images/1061031720286224384/-E24rXom_normal.jpg', u'following': None, u'geo_enabled': True, u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/957651645302624256/1556154548', u'profile_background_image_url': u'', u'name': u'thatstarwarsgirl77', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 6745, u'screen_name': u'thatstarwarsgrl', u'notifications': None, u'url': u'https://www.youtube.com/channel/UCRWsFMLzGGJKLnAXJ9U93_A', u'created_at': u'Sun Jan 28 16:28:39 +0000 2018', u'contributors_enabled': False, u'time_zone': None, u'protected': False, u'translator_type': u'none', u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'lang': u'en', u'created_at': u'Sat Apr 27 20:22:40 +0000 2019', u'filter_level': u'low', u'in_reply_to_status_id_str': None, u'place': None, u'extended_entities': {u'media': [{u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg', u'id_str': u'1122234623407190016', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 462}, u'large': {u'h': 1829, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 815}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623407190016, u'media_url': u'http://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg'}, {u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbJUwAAxes5.jpg', u'id_str': u'1122234623398821888', u'sizes': {u'large': {u'h': 1857, u'resize': u'fit', u'w': 1242}, u'small': {u'h': 680, u'resize': u'fit', u'w': 455}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 803}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623398821888, u'media_url': u'http://pbs.twimg.com/media/D5L6cbJUwAAxes5.jpg'}, {u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbJUUAAzJys.jpg', u'id_str': u'1122234623398793216', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 465}, u'large': {u'h': 1815, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 821}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623398793216, u'media_url': u'http://pbs.twimg.com/media/D5L6cbJUUAAzJys.jpg'}]}}, u'source': u'<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>', u'in_reply_to_screen_name': None, u'id_str': u'1122763172023361537', u'retweet_count': 0, u'in_reply_to_user_id': None, u'favorited': False, u'retweeted_status': {u'quote_count': 7, u'quoted_status_permalink': {u'url': u'/mhZ3FzdyPc.com', u'expanded': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800', u'display': u'twitter.com/thatstarwarsgr\\u2026'}, u'contributors': None, u'truncated': True, u'text': u'imagine thinking 13 million local ig likes is better than ONE BILLION DOLLARS at the worldwide box office cant rela\\u2026 /nS2MbY3ton.com', u'is_quote_status': True, u'in_reply_to_status_id': None, u'reply_count': 11, u'id': 1122490772954075138, u'favorite_count': 4165, u'entities': {u'user_mentions': [], u'symbols': [], u'hashtags': [], u'urls': [{u'url': u'/nS2MbY3to.comn', u'indices': [117, 140], u'expanded_url': u'https://twitter.com/i/web/status/1122490772954075138', u'display_url': u'twitter.com/i/web/status/1\\u2026'}]}, u'quoted_status_id': 1122234629702860800, u'retweeted': False, u'coordinates': None, u'quoted_status': {u'quote_count': 161, u'contributors': None, u'truncated': False, u'text': u'That moment when Kylie Jenner is a better Captain Marvel then the actual Captain Marvel... #captainmarvel /F1GSIW7fpY.com', u'is_quote_status': False, u'in_reply_to_status_id': None, u'reply_count': 128, u'id': 1122234629702860800, u'favorite_count': 434, u'entities': {u'user_mentions': [], u'symbols': [], u'hashtags': [{u'indices': [91, 105], u'text': u'captainmarvel'}], u'urls': [], u'media': [{u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg', u'id_str': u'1122234623407190016', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 462}, u'large': {u'h': 1829, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 815}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623407190016, u'media_url': u'http://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg'}]}, u'retweeted': False, u'coordinates': None, u'source': u'<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>', u'in_reply_to_screen_name': None, u'id_str': u'1122234629702860800', u'display_text_range': [0, 105], u'retweet_count': 68, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': None, u'profile_use_background_image': True, u'default_profile_image': False, u'id': 957651645302624256, u'default_profile': True, u'verified': False, u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/1061031720286224384/-E24rXom_normal.jpg', u'profile_sidebar_fill_color': u'DDEEF6', u'profile_text_color': u'333333', u'followers_count': 7773, u'profile_sidebar_border_color': u'C0DEED', u'id_str': u'957651645302624256', u'profile_background_color': u'F5F8FA', u'listed_count': 36, u'profile_background_image_url_https': u'', u'utc_offset': None, u'statuses_count': 1733, u'description': u'Artist&Youtuber', u'friends_count': 181, u'location': u'California, USA', u'profile_link_color': u'1DA1F2', u'profile_image_url': u'http://pbs.twimg.com/profile_images/1061031720286224384/-E24rXom_normal.jpg', u'following': None, u'geo_enabled': True, u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/957651645302624256/1556154548', u'profile_background_image_url': u'', u'name': u'thatstarwarsgirl77', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 6745, u'screen_name': u'thatstarwarsgrl', u'notifications': None, u'url': u'https://www.youtube.com/channel/UCRWsFMLzGGJKLnAXJ9U93_A', u'created_at': u'Sun Jan 28 16:28:39 +0000 2018', u'contributors_enabled': False, u'time_zone': None, u'protected': False, u'translator_type': u'none', u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'lang': u'en', u'created_at': u'Sat Apr 27 20:22:40 +0000 2019', u'filter_level': u'low', u'in_reply_to_status_id_str': None, u'place': None, u'extended_entities': {u'media': [{u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg', u'id_str': u'1122234623407190016', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 462}, u'large': {u'h': 1829, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 815}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623407190016, u'media_url': u'http://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg'}, {u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbJUwAAxes5.jpg', u'id_str': u'1122234623398821888', u'sizes': {u'large': {u'h': 1857, u'resize': u'fit', u'w': 1242}, u'small': {u'h': 680, u'resize': u'fit', u'w': 455}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 803}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623398821888, u'media_url': u'http://pbs.twimg.com/media/D5L6cbJUwAAxes5.jpg'}, {u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbJUUAAzJys.jpg', u'id_str': u'1122234623398793216', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 465}, u'large': {u'h': 1815, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 821}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623398793216, u'media_url': u'http://pbs.twimg.com/media/D5L6cbJUUAAzJys.jpg'}]}}, u'source': u'<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>', u'in_reply_to_screen_name': None, u'id_str': u'1122490772954075138', u'display_text_range': [0, 140], u'retweet_count': 829, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': None, u'profile_use_background_image': False, u'default_profile_image': False, u'id': 764360805156466689, u'default_profile': False, u'verified': False, u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/1119458374976827393/qGBx6kzg_normal.jpg', u'profile_sidebar_fill_color': u'000000', u'profile_text_color': u'000000', u'followers_count': 1371, u'profile_sidebar_border_color': u'000000', u'id_str': u'764360805156466689', u'profile_background_color': u'000000', u'listed_count': 33, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png', u'utc_offset': None, u'statuses_count': 10165, u'description': u'\\U0001d422\\U0001d427 \\U0001d42d\\U0001d421\\U0001d41a\\U0001d42d \\U0001d428\\U0001d427\\U0001d41e \\U0001d426\\U0001d428\\U0001d426\\U0001d41e\\U0001d427\\U0001d42d, \\U0001d41e\\U0001d42f\\U0001d41e\\U0001d42b\\U0001d432 \\U0001d425\\U0001d422\\U0001d42d\\U0001d42d\\U0001d425\\U0001d41e \\U0001d420\\U0001d422\\U0001d42b\\U0001d425 \\U0001d41f\\U0001d425\\U0001d422\\U0001d41e\\U0001d42c.', u'friends_count': 311, u'location': u'she/her | aos, mcu', u'profile_link_color': u'FAB81E', u'profile_image_url': u'http://pbs.twimg.com/profile_images/1119458374976827393/qGBx6kzg_normal.jpg', u'following': None, u'geo_enabled': False, u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/764360805156466689/1555736437', u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png', u'name': u'\\U0001d42d\\U0001d422\\U0001d41f\\U0001d41f\\u2661 | \\U0001d7cf\\U0001d7d0', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 11917, u'screen_name': u'wondrousIights', u'notifications': None, u'url': None, u'created_at': u'Sat Aug 13 07:19:52 +0000 2016', u'contributors_enabled': False, u'time_zone': None, u'protected': False, u'translator_type': u'none', u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'lang': u'en', u'extended_tweet': {u'display_text_range': [0, 117], u'entities': {u'user_mentions': [], u'symbols': [], u'hashtags': [], u'urls': [{u'url': u'/mhZ3FzdyPc.com', u'indices': [118, 141], u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800', u'display_url': u'twitter.com/thatstarwarsgr\\u2026'}]}, u'full_text': u'imagine thinking 13 million local ig likes is better than ONE BILLION DOLLARS at the worldwide box office cant relate /mhZ3FzdyPc.com'}, u'created_at': u'Sun Apr 28 13:20:29 +0000 2019', u'quoted_status_id_str': u'1122234629702860800', u'filter_level': u'low', u'in_reply_to_status_id_str': None, u'place': None}, u'user': {u'follow_request_sent': None, u'profile_use_background_image': True, u'default_profile_image': False, u'id': 1000815750188294149, u'default_profile': True, u'verified': False, u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/1122160503671926786/_nqEYj6t_normal.jpg', u'profile_sidebar_fill_color': u'DDEEF6', u'profile_text_color': u'333333', u'followers_count': 491, u'profile_sidebar_border_color': u'C0DEED', u'id_str': u'1000815750188294149', u'profile_background_color': u'F5F8FA', u'listed_count': 3, u'profile_background_image_url_https': u'', u'utc_offset': None, u'statuses_count': 15366, u'description': u\"Marvel\\u2022 Hamilton\\u2022 Star Wars\\u2022 Bones\\u2022 B99\\u2022 TGP\\u2022 currently watching Grey's Anatomy\\u2022 fan account                                     \\n\\u2648\\u263c  \\u2651 \\u263e   \\u264d \\u2191\", u'friends_count': 517, u'location': None, u'profile_link_color': u'1DA1F2', u'profile_image_url': u'http://pbs.twimg.com/profile_images/1122160503671926786/_nqEYj6t_normal.jpg', u'following': None, u'geo_enabled': False, u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/1000815750188294149/1552581733', u'profile_background_image_url': u'', u'name': u'\\U0001d544\\U0001d552\\U0001d56a\\U0001d552 \\u2728 saw Endgame and died', u'lang': u'pl', u'profile_background_tile': False, u'favourites_count': 66313, u'screen_name': u'80sSPACEWITCH', u'notifications': None, u'url': None, u'created_at': u'Sun May 27 19:07:23 +0000 2018', u'contributors_enabled': False, u'time_zone': None, u'protected': False, u'translator_type': u'none', u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'lang': u'en', u'created_at': u'Mon Apr 29 07:22:54 +0000 2019', u'quoted_status_id_str': u'1122234629702860800', u'filter_level': u'low', u'in_reply_to_status_id_str': None, u'place': None}"

error image:-

error of when converting string to dict

2 Answers

1
Devesh Kumar Singh On Best Solutions

ast.literal_eval works for me for the value you have provided. Then you can process this dictionary any which way you want to!

import ast

var = "{u'quote_count': 0, u'quoted_status_permalink': {u'url': u'/mhZ3FzdyPc.com', u'expanded': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800', u'display': u'twitter.com/thatstarwarsgr\\u2026'}, u'contributors': None, u'truncated': False, u'text': u'RT @wondrousIights: imagine thinking 13 million local ig likes is better than ONE BILLION DOLLARS at the worldwide box office cant relate h\\u2026', u'is_quote_status': True, u'in_reply_to_status_id': None, u'reply_count': 0, u'id': 1122763172023361537, u'favorite_count': 0, u'entities': {u'user_mentions': [{u'id': 764360805156466689, u'indices': [3, 18], u'id_str': u'764360805156466689', u'screen_name': u'wondrousIights', u'name': u'\\U0001d42d\\U0001d422\\U0001d41f\\U0001d41f\\u2661 | \\U0001d7cf\\U0001d7d0'}], u'symbols': [], u'hashtags': [], u'urls': []}, u'quoted_status_id': 1122234629702860800, u'retweeted': False, u'coordinates': None, u'timestamp_ms': u'1556522574798', u'quoted_status': {u'quote_count': 161, u'contributors': None, u'truncated': False, u'text': u'That moment when Kylie Jenner is a better Captain Marvel then the actual Captain Marvel... #captainmarvel /F1GSIW7fpY.com', u'is_quote_status': False, u'in_reply_to_status_id': None, u'reply_count': 128, u'id': 1122234629702860800, u'favorite_count': 434, u'entities': {u'user_mentions': [], u'symbols': [], u'hashtags': [{u'indices': [91, 105], u'text': u'captainmarvel'}], u'urls': [], u'media': [{u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg', u'id_str': u'1122234623407190016', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 462}, u'large': {u'h': 1829, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 815}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623407190016, u'media_url': u'http://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg'}]}, u'retweeted': False, u'coordinates': None, u'source': u'<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>', u'in_reply_to_screen_name': None, u'id_str': u'1122234629702860800', u'display_text_range': [0, 105], u'retweet_count': 68, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': None, u'profile_use_background_image': True, u'default_profile_image': False, u'id': 957651645302624256, u'default_profile': True, u'verified': False, u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/1061031720286224384/-E24rXom_normal.jpg', u'profile_sidebar_fill_color': u'DDEEF6', u'profile_text_color': u'333333', u'followers_count': 7773, u'profile_sidebar_border_color': u'C0DEED', u'id_str': u'957651645302624256', u'profile_background_color': u'F5F8FA', u'listed_count': 36, u'profile_background_image_url_https': u'', u'utc_offset': None, u'statuses_count': 1733, u'description': u'Artist&Youtuber', u'friends_count': 181, u'location': u'California, USA', u'profile_link_color': u'1DA1F2', u'profile_image_url': u'http://pbs.twimg.com/profile_images/1061031720286224384/-E24rXom_normal.jpg', u'following': None, u'geo_enabled': True, u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/957651645302624256/1556154548', u'profile_background_image_url': u'', u'name': u'thatstarwarsgirl77', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 6745, u'screen_name': u'thatstarwarsgrl', u'notifications': None, u'url': u'https://www.youtube.com/channel/UCRWsFMLzGGJKLnAXJ9U93_A', u'created_at': u'Sun Jan 28 16:28:39 +0000 2018', u'contributors_enabled': False, u'time_zone': None, u'protected': False, u'translator_type': u'none', u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'lang': u'en', u'created_at': u'Sat Apr 27 20:22:40 +0000 2019', u'filter_level': u'low', u'in_reply_to_status_id_str': None, u'place': None, u'extended_entities': {u'media': [{u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg', u'id_str': u'1122234623407190016', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 462}, u'large': {u'h': 1829, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 815}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623407190016, u'media_url': u'http://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg'}, {u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbJUwAAxes5.jpg', u'id_str': u'1122234623398821888', u'sizes': {u'large': {u'h': 1857, u'resize': u'fit', u'w': 1242}, u'small': {u'h': 680, u'resize': u'fit', u'w': 455}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 803}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623398821888, u'media_url': u'http://pbs.twimg.com/media/D5L6cbJUwAAxes5.jpg'}, {u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbJUUAAzJys.jpg', u'id_str': u'1122234623398793216', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 465}, u'large': {u'h': 1815, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 821}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623398793216, u'media_url': u'http://pbs.twimg.com/media/D5L6cbJUUAAzJys.jpg'}]}}, u'source': u'<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>', u'in_reply_to_screen_name': None, u'id_str': u'1122763172023361537', u'retweet_count': 0, u'in_reply_to_user_id': None, u'favorited': False, u'retweeted_status': {u'quote_count': 7, u'quoted_status_permalink': {u'url': u'/mhZ3FzdyPc.com', u'expanded': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800', u'display': u'twitter.com/thatstarwarsgr\\u2026'}, u'contributors': None, u'truncated': True, u'text': u'imagine thinking 13 million local ig likes is better than ONE BILLION DOLLARS at the worldwide box office cant rela\\u2026 /nS2MbY3ton.com', u'is_quote_status': True, u'in_reply_to_status_id': None, u'reply_count': 11, u'id': 1122490772954075138, u'favorite_count': 4165, u'entities': {u'user_mentions': [], u'symbols': [], u'hashtags': [], u'urls': [{u'url': u'/nS2MbY3to.comn', u'indices': [117, 140], u'expanded_url': u'https://twitter.com/i/web/status/1122490772954075138', u'display_url': u'twitter.com/i/web/status/1\\u2026'}]}, u'quoted_status_id': 1122234629702860800, u'retweeted': False, u'coordinates': None, u'quoted_status': {u'quote_count': 161, u'contributors': None, u'truncated': False, u'text': u'That moment when Kylie Jenner is a better Captain Marvel then the actual Captain Marvel... #captainmarvel /F1GSIW7fpY.com', u'is_quote_status': False, u'in_reply_to_status_id': None, u'reply_count': 128, u'id': 1122234629702860800, u'favorite_count': 434, u'entities': {u'user_mentions': [], u'symbols': [], u'hashtags': [{u'indices': [91, 105], u'text': u'captainmarvel'}], u'urls': [], u'media': [{u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg', u'id_str': u'1122234623407190016', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 462}, u'large': {u'h': 1829, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 815}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623407190016, u'media_url': u'http://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg'}]}, u'retweeted': False, u'coordinates': None, u'source': u'<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>', u'in_reply_to_screen_name': None, u'id_str': u'1122234629702860800', u'display_text_range': [0, 105], u'retweet_count': 68, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': None, u'profile_use_background_image': True, u'default_profile_image': False, u'id': 957651645302624256, u'default_profile': True, u'verified': False, u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/1061031720286224384/-E24rXom_normal.jpg', u'profile_sidebar_fill_color': u'DDEEF6', u'profile_text_color': u'333333', u'followers_count': 7773, u'profile_sidebar_border_color': u'C0DEED', u'id_str': u'957651645302624256', u'profile_background_color': u'F5F8FA', u'listed_count': 36, u'profile_background_image_url_https': u'', u'utc_offset': None, u'statuses_count': 1733, u'description': u'Artist&Youtuber', u'friends_count': 181, u'location': u'California, USA', u'profile_link_color': u'1DA1F2', u'profile_image_url': u'http://pbs.twimg.com/profile_images/1061031720286224384/-E24rXom_normal.jpg', u'following': None, u'geo_enabled': True, u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/957651645302624256/1556154548', u'profile_background_image_url': u'', u'name': u'thatstarwarsgirl77', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 6745, u'screen_name': u'thatstarwarsgrl', u'notifications': None, u'url': u'https://www.youtube.com/channel/UCRWsFMLzGGJKLnAXJ9U93_A', u'created_at': u'Sun Jan 28 16:28:39 +0000 2018', u'contributors_enabled': False, u'time_zone': None, u'protected': False, u'translator_type': u'none', u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'lang': u'en', u'created_at': u'Sat Apr 27 20:22:40 +0000 2019', u'filter_level': u'low', u'in_reply_to_status_id_str': None, u'place': None, u'extended_entities': {u'media': [{u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg', u'id_str': u'1122234623407190016', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 462}, u'large': {u'h': 1829, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 815}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623407190016, u'media_url': u'http://pbs.twimg.com/media/D5L6cbLUcAAA7cQ.jpg'}, {u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbJUwAAxes5.jpg', u'id_str': u'1122234623398821888', u'sizes': {u'large': {u'h': 1857, u'resize': u'fit', u'w': 1242}, u'small': {u'h': 680, u'resize': u'fit', u'w': 455}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 803}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623398821888, u'media_url': u'http://pbs.twimg.com/media/D5L6cbJUwAAxes5.jpg'}, {u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800/photo/1', u'display_url': u'pic.twitter.com/F1GSIW7fpY', u'url': u'/F1GSIW7fpY.com', u'media_url_https': u'https://pbs.twimg.com/media/D5L6cbJUUAAzJys.jpg', u'id_str': u'1122234623398793216', u'sizes': {u'small': {u'h': 680, u'resize': u'fit', u'w': 465}, u'large': {u'h': 1815, u'resize': u'fit', u'w': 1242}, u'medium': {u'h': 1200, u'resize': u'fit', u'w': 821}, u'thumb': {u'h': 150, u'resize': u'crop', u'w': 150}}, u'indices': [106, 129], u'type': u'photo', u'id': 1122234623398793216, u'media_url': u'http://pbs.twimg.com/media/D5L6cbJUUAAzJys.jpg'}]}}, u'source': u'<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>', u'in_reply_to_screen_name': None, u'id_str': u'1122490772954075138', u'display_text_range': [0, 140], u'retweet_count': 829, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': None, u'profile_use_background_image': False, u'default_profile_image': False, u'id': 764360805156466689, u'default_profile': False, u'verified': False, u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/1119458374976827393/qGBx6kzg_normal.jpg', u'profile_sidebar_fill_color': u'000000', u'profile_text_color': u'000000', u'followers_count': 1371, u'profile_sidebar_border_color': u'000000', u'id_str': u'764360805156466689', u'profile_background_color': u'000000', u'listed_count': 33, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png', u'utc_offset': None, u'statuses_count': 10165, u'description': u'\\U0001d422\\U0001d427 \\U0001d42d\\U0001d421\\U0001d41a\\U0001d42d \\U0001d428\\U0001d427\\U0001d41e \\U0001d426\\U0001d428\\U0001d426\\U0001d41e\\U0001d427\\U0001d42d, \\U0001d41e\\U0001d42f\\U0001d41e\\U0001d42b\\U0001d432 \\U0001d425\\U0001d422\\U0001d42d\\U0001d42d\\U0001d425\\U0001d41e \\U0001d420\\U0001d422\\U0001d42b\\U0001d425 \\U0001d41f\\U0001d425\\U0001d422\\U0001d41e\\U0001d42c.', u'friends_count': 311, u'location': u'she/her | aos, mcu', u'profile_link_color': u'FAB81E', u'profile_image_url': u'http://pbs.twimg.com/profile_images/1119458374976827393/qGBx6kzg_normal.jpg', u'following': None, u'geo_enabled': False, u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/764360805156466689/1555736437', u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png', u'name': u'\\U0001d42d\\U0001d422\\U0001d41f\\U0001d41f\\u2661 | \\U0001d7cf\\U0001d7d0', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 11917, u'screen_name': u'wondrousIights', u'notifications': None, u'url': None, u'created_at': u'Sat Aug 13 07:19:52 +0000 2016', u'contributors_enabled': False, u'time_zone': None, u'protected': False, u'translator_type': u'none', u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'lang': u'en', u'extended_tweet': {u'display_text_range': [0, 117], u'entities': {u'user_mentions': [], u'symbols': [], u'hashtags': [], u'urls': [{u'url': u'/mhZ3FzdyPc.com', u'indices': [118, 141], u'expanded_url': u'https://twitter.com/thatstarwarsgrl/status/1122234629702860800', u'display_url': u'twitter.com/thatstarwarsgr\\u2026'}]}, u'full_text': u'imagine thinking 13 million local ig likes is better than ONE BILLION DOLLARS at the worldwide box office cant relate /mhZ3FzdyPc.com'}, u'created_at': u'Sun Apr 28 13:20:29 +0000 2019', u'quoted_status_id_str': u'1122234629702860800', u'filter_level': u'low', u'in_reply_to_status_id_str': None, u'place': None}, u'user': {u'follow_request_sent': None, u'profile_use_background_image': True, u'default_profile_image': False, u'id': 1000815750188294149, u'default_profile': True, u'verified': False, u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/1122160503671926786/_nqEYj6t_normal.jpg', u'profile_sidebar_fill_color': u'DDEEF6', u'profile_text_color': u'333333', u'followers_count': 491, u'profile_sidebar_border_color': u'C0DEED', u'id_str': u'1000815750188294149', u'profile_background_color': u'F5F8FA', u'listed_count': 3, u'profile_background_image_url_https': u'', u'utc_offset': None, u'statuses_count': 15366, u'description': u\"Marvel\\u2022 Hamilton\\u2022 Star Wars\\u2022 Bones\\u2022 B99\\u2022 TGP\\u2022 currently watching Grey's Anatomy\\u2022 fan account                                     \\n\\u2648\\u263c  \\u2651 \\u263e   \\u264d \\u2191\", u'friends_count': 517, u'location': None, u'profile_link_color': u'1DA1F2', u'profile_image_url': u'http://pbs.twimg.com/profile_images/1122160503671926786/_nqEYj6t_normal.jpg', u'following': None, u'geo_enabled': False, u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/1000815750188294149/1552581733', u'profile_background_image_url': u'', u'name': u'\\U0001d544\\U0001d552\\U0001d56a\\U0001d552 \\u2728 saw Endgame and died', u'lang': u'pl', u'profile_background_tile': False, u'favourites_count': 66313, u'screen_name': u'80sSPACEWITCH', u'notifications': None, u'url': None, u'created_at': u'Sun May 27 19:07:23 +0000 2018', u'contributors_enabled': False, u'time_zone': None, u'protected': False, u'translator_type': u'none', u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'lang': u'en', u'created_at': u'Mon Apr 29 07:22:54 +0000 2019', u'quoted_status_id_str': u'1122234629702860800', u'filter_level': u'low', u'in_reply_to_status_id_str': None, u'place': None}"

dct = ast.literal_eval(var)
print(type(dct))
#<class 'dict'>
-2
Roee Barak On

ast.literal_eval should receive strings. However in the KafkaConsumer Documentation it says:

message value and key are raw bytes -- decode if necessary!

So your decision in the above line to insert string into str() before treating it as a string was correct. However in the following line you didn't do it. I would recommend to replace that line with:

dict=ast.literal_eval(str(string))

and see what happens.