{"action":"closed","issue":{"url":"https://api.github.com/repos/web2py/web2py/issues/1089","labels_url":"https://api.github.com/repos/web2py/web2py/issues/1089/labels{/name}","comments_url":"https://api.github.com/repos/web2py/web2py/issues/1089/comments","events_url":"https://api.github.com/repos/web2py/web2py/issues/1089/events","html_url":"https://github.com/web2py/web2py/issues/1089","id":113124227,"number":1089,"title":"encode issue on globals.py - json ","user":{"login":"sharkguto","id":3118165,"avatar_url":"https://avatars.githubusercontent.com/u/3118165?v=3","gravatar_id":"","url":"https://api.github.com/users/sharkguto","html_url":"https://github.com/sharkguto","followers_url":"https://api.github.com/users/sharkguto/followers","following_url":"https://api.github.com/users/sharkguto/following{/other_user}","gists_url":"https://api.github.com/users/sharkguto/gists{/gist_id}","starred_url":"https://api.github.com/users/sharkguto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharkguto/subscriptions","organizations_url":"https://api.github.com/users/sharkguto/orgs","repos_url":"https://api.github.com/users/sharkguto/repos","events_url":"https://api.github.com/users/sharkguto/events{/privacy}","received_events_url":"https://api.github.com/users/sharkguto/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-24T01:07:30Z","updated_at":"2015-11-17T19:54:20Z","closed_at":"2015-11-17T19:54:19Z","body":"Hi guys,\r\n\r\nI have create some threads on web2py groups without answer.\r\n\r\nI found a bug on globals.py. When i send a application/json with encode iso-8859-1 i got no post_vars.... always came empty.\r\n\r\nas following images, when I send a json without special chars it works, however when i send with \"ç\", bring me nothing.\r\n\r\n\r\n\r\n![](https://lh3.googleusercontent.com/-r8GjAiTok5M/VimiJvEYNRI/AAAAAAAACW8/PTjxELAaWfM/s1600/2015_10_23_00_11_54_SoapUI_5.2.1.png)\r\n\r\n![](https://lh3.googleusercontent.com/-rA7DHfSXQvE/Vimh6wzWrwI/AAAAAAAACWk/Xrs-cgv8Dc4/s1600/2015-10-23%2B00_14_44-Editing%2BAddUpdateAddress.png)\r\n\r\n![](https://lh3.googleusercontent.com/-FxF8JOqBBes/Vimh7ddrGtI/AAAAAAAACWs/a_Vb4dKM3ZA/s1600/2015-10-23%2B00_05_56-SoapUI%2B5.2.1.png)\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n\r\nThis is my fix:\r\n\r\npost_vars = self._post_vars = Storage()\r\n        body = self.body\r\n        #import copy\r\n        #body2 = copy.copy(self.body) #self.body\r\n        # if content-type is application/json, we must read the body\r\n        is_json = env.get('content_type', '')[:16] == 'application/json'\r\n        #body2 = body.read()\r\n        #body.seek(0)\r\n        if is_json:\r\n            try:\r\n                json_vars = sj.load(body)\r\n                #print json_vars\r\n            except Exception, e:\r\n                #print str(e)\r\n                body.seek(0)\r\n                body2 = body.read()\r\n\r\n                try:\r\n                    print chardet.detect(body2)['encoding']\r\n                    body_encoded = body2.decode(chardet.detect(body2)['encoding']).encode('utf-8')\r\n                    json_vars = sj.loads(body_encoded)\r\n                except Exception, e:\r\n                    print str(e)\r\n                    json_vars = {}\r\n                # incoherent request bodies can still be parsed \"ad-hoc\"\r\n                #json_vars = {\"oloko\":str(e)}\r\n                pass\r\n            # update vars and get_vars with what was posted as json\r\n            if isinstance(json_vars, dict):\r\n                post_vars.update(json_vars)\r\n\r\n\r\n![image](https://cloud.githubusercontent.com/assets/3118165/10708014/a9f5f616-79d9-11e5-8bd8-79f19caf8e13.png)\r\n\r\n\r\n\r\nI do not know if this solution is the better, but solve my problem.\r\nSorry about my english, i am not native.\r\n\r\nU guys can take a look on this issue for the next release?\r\n\r\n\r\nGrateful for attention\r\n\r\nGustavo M Freitas"}}