Skip to content

Commit

Permalink
Call json.loads methods with strict=False
Browse files Browse the repository at this point in the history
View more information about this in pull request wechatpy#154
  • Loading branch information
messense committed Jun 5, 2016
1 parent de5bea9 commit 3d9fa43
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
3 changes: 1 addition & 2 deletions wechatpy/client/base.py
Expand Up @@ -111,9 +111,8 @@ def _request(self, method, url_or_endpoint, **kwargs):
)

def _decode_result(self, res):
res.encoding = 'utf-8'
try:
result = json.loads(res.content.decode('utf-8', 'ignore'))
result = json.loads(res.content.decode('utf-8', 'ignore'), strict=False)
except (TypeError, ValueError):
# Return origin response object if we can not decode it as JSON
return res
Expand Down
5 changes: 2 additions & 3 deletions wechatpy/component.py
Expand Up @@ -10,12 +10,11 @@
"""
from __future__ import absolute_import, unicode_literals
import time
import json
import six
import requests
import xmltodict

from wechatpy.utils import to_text, to_binary, get_querystring
from wechatpy.utils import to_text, to_binary, get_querystring, json
from wechatpy.fields import StringField, DateTimeField
from wechatpy.messages import MessageMetaClass
from wechatpy.session.memorystorage import MemoryStorage
Expand Down Expand Up @@ -136,7 +135,7 @@ def _request(self, method, url_or_endpoint, **kwargs):
return self._handle_result(res, method, url, **kwargs)

def _handle_result(self, res, method=None, url=None, **kwargs):
result = res.json()
result = json.loads(res.content.decode('utf-8', 'ignore'), strict=False)
if 'errcode' in result:
result['errcode'] = int(result['errcode'])

Expand Down
3 changes: 1 addition & 2 deletions wechatpy/oauth/__init__.py
Expand Up @@ -73,8 +73,7 @@ def _request(self, method, url_or_endpoint, **kwargs):
request=reqe.request,
response=reqe.response
)
res.encoding = 'UTF-8'
result = res.json()
result = json.loads(res.content.decode('utf-8', 'ignore'), strict=False)

if 'errcode' in result and result['errcode'] != 0:
errcode = result['errcode']
Expand Down

0 comments on commit 3d9fa43

Please sign in to comment.