Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
url = url_or_endpoint
if isinstance(kwargs.get('data', ''), dict):
body = json.dumps(kwargs['data'], ensure_ascii=False)
body = body.encode('utf-8')
kwargs['data'] = body
res = self._http.request(
method=method,
url=url,
**kwargs
)
try:
res.raise_for_status()
except requests.RequestException as reqe:
raise WeChatOAuthException(
errcode=None,
errmsg=None,
client=self,
request=reqe.request,
response=reqe.response
)
result = json.loads(res.content.decode('utf-8', 'ignore'), strict=False)
if 'errcode' in result and result['errcode'] != 0:
errcode = result['errcode']
errmsg = result['errmsg']
raise WeChatOAuthException(
errcode,
errmsg,
client=self,
request=res.request,
try:
res.raise_for_status()
except requests.RequestException as reqe:
raise WeChatOAuthException(
errcode=None,
errmsg=None,
client=self,
request=reqe.request,
response=reqe.response
)
result = json.loads(res.content.decode('utf-8', 'ignore'), strict=False)
if 'errcode' in result and result['errcode'] != 0:
errcode = result['errcode']
errmsg = result['errmsg']
raise WeChatOAuthException(
errcode,
errmsg,
client=self,
request=res.request,
response=res
)
return result
if 'micromessenger' in user_agent:
app_id = current_app.config['WECHAT_APPID']
secret = current_app.config['WECHAT_SECRET']
url_method = 'authorize_url'
else:
app_id = current_app.config['WECHAT_OPEN_APP_ID']
secret = current_app.config['WECHAT_OPEN_APP_SECRET']
url_method = 'qrconnect_url'
wechat_oauth = WeChatOAuth(app_id, secret, redirect_uri, scope, _state)
user = check_func()
if request.args.get('code') and not user:
try:
res = wechat_oauth.fetch_access_token(request.args['code'])
except WeChatOAuthException:
return abort(403)
else:
if scope == 'snsapi_base':
set_user(res)
else:
user_info = wechat_oauth.get_user_info()
set_user(user_info)
elif not user:
return redirect(getattr(wechat_oauth, url_method))
return method(*args, **kwargs)
return wrapper