{"id":306,"date":"2013-10-18T16:25:24","date_gmt":"2013-10-18T20:25:24","guid":{"rendered":"http:\/\/digitallibraryworld.com\/?p=306"},"modified":"2013-10-18T16:25:24","modified_gmt":"2013-10-18T20:25:24","slug":"python-dictionary-is-not-accessible-in-google-app-engine-using-square-brackets","status":"publish","type":"post","link":"https:\/\/heisbudi.com\/?p=306","title":{"rendered":"Python dictionary is not accessible in Google App Engine using square brackets"},"content":{"rendered":"<p>My code is pulling JSON data from a web service I wrote. That JSON data is then loaded into a python dictionary. Things works fabulously when I debug in my local console running an internal web server provided by the App Engine SDK. But when I upload the application to Goole CLoud Engine, things break. This is a snippet of my code<\/p>\n<pre lang=\"python\">states=dict()\r\npopulation_data=\"\"\r\nurl=\"http:\/\/something.com\/json\"\r\ntry:\r\n   response=urllib2.urlopen(url)\r\n   states=json.load(response,\"utf-8\")\r\nexcept Exception as ex:\r\n   self.response.write(\"Google says: %s\"%(ex.message))\r\n   self.response.write(\"Try refreshing the page (again)\")\r\n   SystemExit(0)<\/pre>\n<p>I have all the states abbreviation as keys. when I try to access the value of the dictionary directly using square brackets, like<\/p>\n<pre lang=\"python\">states[\"IN\"]<\/pre>\n<p>Google App Engine complains about KeyError exception.  However if I try iterating through the key using a for loop, like<\/p>\n<pre lang=\"python\">for each_state in states:\r\n   self.response.write(states[each_state])<\/pre>\n<p>it works flawlessly in the App Engine. I also found out that the following also works perfectly<\/p>\n<pre lang=\"python\">self.response.write(states.get(\"IN\"))<\/pre>\n<p>The only thing I cannot do is accessing the dictionary using square brackets. That baffles me. If you know what&#8217;s up with that, drop me a line.<\/p>\n<div data-counters='1' data-style='square' data-size='regular' data-url='https:\/\/heisbudi.com\/?p=306' data-title='Python dictionary is not accessible in Google App Engine using square brackets' class='linksalpha_container linksalpha_app_3'><a href='\/\/www.linksalpha.com\/share?network='facebook' class='linksalpha_icon_facebook'><\/a><a href='\/\/www.linksalpha.com\/share?network='twitter' class='linksalpha_icon_twitter'><\/a><a href='\/\/www.linksalpha.com\/share?network='googleplus' class='linksalpha_icon_googleplus'><\/a><a href='\/\/www.linksalpha.com\/share?network='mail' class='linksalpha_icon_mail'><\/a><\/div><div data-position='' data-url='https:\/\/heisbudi.com\/?p=306' data-title='Python dictionary is not accessible in Google App Engine using square brackets' class='linksalpha_container linksalpha_app_7'><a href='\/\/www.linksalpha.com\/share?network='facebook' class='linksalpha_icon_facebook'><\/a><a href='\/\/www.linksalpha.com\/share?network='twitter' class='linksalpha_icon_twitter'><\/a><a href='\/\/www.linksalpha.com\/share?network='googleplus' class='linksalpha_icon_googleplus'><\/a><a href='\/\/www.linksalpha.com\/share?network='mail' class='linksalpha_icon_mail'><\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>My code is pulling JSON data from a web service I wrote. That JSON data is then loaded into a python dictionary. Things works fabulously when I debug in my local console running an internal web server provided by the App Engine SDK. But when I upload the application to Goole CLoud Engine, things break. <a class=\"read-more\" href=\"https:\/\/heisbudi.com\/?p=306\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27,26],"tags":[],"_links":{"self":[{"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/posts\/306"}],"collection":[{"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/heisbudi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=306"}],"version-history":[{"count":6,"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/posts\/306\/revisions"}],"predecessor-version":[{"id":377,"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/posts\/306\/revisions\/377"}],"wp:attachment":[{"href":"https:\/\/heisbudi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/heisbudi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/heisbudi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}