How to use the wechatpy.exceptions.WeChatOAuthException function in wechatpy

To help you get started, we’ve selected a few wechatpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jxtech / wechatpy / wechatpy / oauth.py View on Github external
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,
github jxtech / wechatpy / wechatpy / oauth.py View on Github external
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
github cloverstd / flask-wechatpy / flask_wechatpy / __init__.py View on Github external
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