wechat_sdk/lib/request.py
def request(self, method, url, access_token=None, **kwargs):
        """
        向微信服务器发送请求
        :param method: 请求方法
        :param url: 请求地址
        :param access_token: access token 值, 如果初始化时传入 conf 会自动获取, 如果没有传入则请提供此值
        :param kwargs: 附加数据
        :return: 微信服务器响应的 JSON 数据
        """
        access_token = self.__conf.access_token if self.__conf is not None else access_token
        if "params" not in kwargs:
            kwargs["params"] = {
                "access_token": access_token
            }
        else:
            kwargs["params"]["access_token"] = access_token

        if isinstance(kwargs.get("data", ""), dict):
            body = json.dumps(kwargs["data"], ensure_ascii=False)
            if isinstance(body, six.text_type):
                body = body.encode('utf8')
            kwargs["data"] = body

        r = requests.request(
            method=method,
            url=url,
            **kwargs
        )
        r.raise_for_status()
        try:
            response_json = r.json()
        except ValueError:  # 非 JSON 数据
            return r

        headimgurl = response_json.get('headimgurl')
        if headimgurl:
            response_json['headimgurl'] = headimgurl.replace('\\', '')
        self._check_official_error(response_json)
        return response_json
def request(self, method, url, access_token=None, **kwargs):
        """
        向微信服务器发送请求
        :param method: 请求方法
        :param url: 请求地址
        :param access_token: access token 值, 如果初始化时传入 conf 会自动获取, 如果没有传入则请提供此值
        :param kwargs: 附加数据
        :return: 微信服务器响应的 JSON 数据
        """
        access_token = self.__conf.access_token if self.__conf is not None else access_token
        if "params" not in kwargs:
            kwargs["params"] = {
                "access_token": access_token
            }
        else:
            kwargs["params"]["access_token"] = access_token

        if isinstance(kwargs.get("data", ""), dict):
            body = json.dumps(kwargs["data"], ensure_ascii=False)
            if isinstance(body, six.text_type):
                body = body.encode('utf8')
            kwargs["data"] = body

        r = requests.request(
            method=method,
            url=url,
            **kwargs
        )
        r.raise_for_status()
        try:
            response_json = r.json()
        except ValueError:  # 非 JSON 数据
            return r

        headimgurl = response_json.get('headimgurl')
        if headimgurl:
            response_json['headimgurl'] = headimgurl.replace('\\', '')
        self._check_official_error(response_json)
        return response_json
def request ( self , method , url , access_token = None , * * kwargs ) : access_token = self . __conf . access_token if self . __conf is not None else access_token if "params" not in kwargs : kwargs [ "params" ] = { "access_token" : access_token } else : kwargs [ "params" ] [ "access_token" ] = access_token if isinstance ( kwargs . get ( "data" , "" ) , dict ) : body = json . dumps ( kwargs [ "data" ] , ensure_ascii = False ) if isinstance ( body , six . text_type ) : body = body . encode ( 'utf8' ) kwargs [ "data" ] = body r = requests . request ( method = method , url = url , * * kwargs ) r . raise_for_status ( ) try : response_json = r . json ( ) except ValueError : # 非 JSON 数据 return r headimgurl = response_json . get ( 'headimgurl' ) if headimgurl : response_json [ 'headimgurl' ] = headimgurl . replace ( '\\' , '' ) self . _check_official_error ( response_json ) return response_json
向微信服务器发送请求
        :param method: 请求方法
        :param url: 请求地址
        :param access_token: access token 值, 如果初始化时传入 conf 会自动获取, 如果没有传入则请提供此值
        :param kwargs: 附加数据
        :return: 微信服务器响应的 JSON 数据
向微信服务器发送请求 : param method : 请求方法 : param url : 请求地址 : param access_token : access token 值 如果初始化时传入 conf 会自动获取 如果没有传入则请提供此值 : param kwargs : 附加数据 : return : 微信服务器响应的 JSON 数据