Python JSON: NameError: name false is not defined
Python JSON: NameError: name false is not defined
You are trying to paste the string straight into Python. Dont do that, it is a string sequence that represents objects.
JSON only looks a lot like Python, but it is not actual Python code.
Here I loaded this as a raw Python string to not interpret any escapes in it:
>>> import json
>>> json_string = r{created_at:Thu Jul 10 20:02:00 +0000 2014,id:487325888950710272,id_str:487325888950710272,text:u5f81u9678u300cu5de6u8155u306eu7fa9u624bu306fu30dbu30edu3060u300d,source:u003ca href=http://twittbot.net/ rel=nofollow\u003etwittbot.netu003c/au003e,truncated:false,in_reply_to_status_id:null,in_reply_to_status_id_str:null,in_reply_to_user_id:null,in_reply_to_user_id_str:null,in_reply_to_screen_name:null,user:{id:1429838018,id_str:1429838018,name:u3053u3093u306auff30uff30u306fu5accu3060u3002,screen_name:iyada_pp,location:u516cu5b89u5c40u306eu3069u3053u304bu3002,url:null,description:u3010u3053u3093u306aPSYCHO-PASSu306fu5accu3060u306au3011u3068u3044u3046u304fu3060u3089u306au3044u5984u60f3botu3067u3059u3002u30adu30e3u30e9u5d29u58cau304cu6fc0u3057u3044u306eu3067u3054u6ce8u610fu304fu3060u3055u3044u3002,protected:false,followers_count:99,friends_count:98,listed_count:5,created_at:Wed May 15 07:52:33 +0000 2013,favourites_count:0,utc_offset:null,time_zone:null,geo_enabled:false,verified:false,statuses_count:12584,lang:ja,contributors_enabled:false,is_translator:false,is_translation_enabled:false,profile_background_color:C0DEED,profile_background_image_url:http://abs.twimg.com/images/themes/theme1/bg.png,profile_background_image_url_https:https://abs.twimg.com/images/themes/theme1/bg.png,profile_background_tile:false,profile_image_url:http://pbs.twimg.com/profile_images/3661872276/ab7201283dac5dc1789bb6dfa9b6abe4_normal.jpeg,profile_image_url_https:https://pbs.twimg.com/profile_images/3661872276/ab7201283dac5dc1789bb6dfa9b6abe4_normal.jpeg,profile_link_color:0084B4,profile_sidebar_border_color:C0DEED,profile_sidebar_fill_color:DDEEF6,profile_text_color:333333,profile_use_background_image:true,default_profile:true,default_profile_image:false,following:null,follow_request_sent:null,notifications:null},geo:null,coordinates:null,place:null,contributors:null,retweet_count:0,favorite_count:0,entities:{hashtags:[],symbols:[],urls:[],user_mentions:[]},favorited:false,retweeted:false,filter_level:medium,lang:ja}
>>> json.loads(json_string)
{ucontributors: None, utruncated: False, utext: uu5f81u9678u300cu5de6u8155u306eu7fa9u624bu306fu30dbu30edu3060u300d, uin_reply_to_status_id: None, uid: 487325888950710272, ufavorite_count: 0, usource: u<a href=http://twittbot.net/ rel=nofollow>twittbot.net</a>, uretweeted: False, ucoordinates: None, uentities: {usymbols: [], uuser_mentions: [], uhashtags: [], uurls: []}, uin_reply_to_screen_name: None, uid_str: u487325888950710272, uretweet_count: 0, uin_reply_to_user_id: None, ufavorited: False, uuser: {ufollow_request_sent: None, uprofile_use_background_image: True, udefault_profile_image: False, uid: 1429838018, uprofile_background_image_url_https: uhttps://abs.twimg.com/images/themes/theme1/bg.png, uverified: False, uprofile_image_url_https: uhttps://pbs.twimg.com/profile_images/3661872276/ab7201283dac5dc1789bb6dfa9b6abe4_normal.jpeg, uprofile_sidebar_fill_color: uDDEEF6, uprofile_text_color: u333333, ufollowers_count: 99, uprofile_sidebar_border_color: uC0DEED, uid_str: u1429838018, uprofile_background_color: uC0DEED, ulisted_count: 5, uis_translation_enabled: False, uutc_offset: None, ustatuses_count: 12584, udescription: uu3010u3053u3093u306aPSYCHO-PASSu306fu5accu3060u306au3011u3068u3044u3046u304fu3060u3089u306au3044u5984u60f3botu3067u3059u3002u30adu30e3u30e9u5d29u58cau304cu6fc0u3057u3044u306eu3067u3054u6ce8u610fu304fu3060u3055u3044u3002, ufriends_count: 98, ulocation: uu516cu5b89u5c40u306eu3069u3053u304bu3002, uprofile_link_color: u0084B4, uprofile_image_url: uhttp://pbs.twimg.com/profile_images/3661872276/ab7201283dac5dc1789bb6dfa9b6abe4_normal.jpeg, ufollowing: None, ugeo_enabled: False, uprofile_background_image_url: uhttp://abs.twimg.com/images/themes/theme1/bg.png, uname: uu3053u3093u306auff30uff30u306fu5accu3060u3002, ulang: uja, uprofile_background_tile: False, ufavourites_count: 0, uscreen_name: uiyada_pp, unotifications: None, uurl: None, ucreated_at: uWed May 15 07:52:33 +0000 2013, ucontributors_enabled: False, utime_zone: None, uprotected: False, udefault_profile: True, uis_translator: False}, ugeo: None, uin_reply_to_user_id_str: None, ulang: uja, ucreated_at: uThu Jul 10 20:02:00 +0000 2014, ufilter_level: umedium, uin_reply_to_status_id_str: None, uplace: None}
Just define false
to False
before converting to json.
false = False
This answer is inspired from this answer
Python JSON: NameError: name false is not defined
the twitter stream gives you a Unicode string literal. you can check the same by using
type(data)
You will need to decode the data into UTF-8 before using the JSON deserialization for eg.
json.loads(data.decode(utf-8))
and then use the dictionary to process the stream. Good luck