MCPcopy Create free account
hub / github.com/doraemonext/wechat-python-sdk / request

Method request

wechat_sdk/lib/request.py:22–60  ·  view source on GitHub ↗

向微信服务器发送请求 :param method: 请求方法 :param url: 请求地址 :param access_token: access token 值, 如果初始化时传入 conf 会自动获取, 如果没有传入则请提供此值 :param kwargs: 附加数据 :return: 微信服务器响应的 JSON 数据

(self, method, url, access_token=None, **kwargs)

Source from the content-addressed store, hash-verified

20 self.__conf = conf
21
22 def request(self, method, url, access_token=None, **kwargs):
23 """
24 向微信服务器发送请求
25 :param method: 请求方法
26 :param url: 请求地址
27 :param access_token: access token 值, 如果初始化时传入 conf 会自动获取, 如果没有传入则请提供此值
28 :param kwargs: 附加数据
29 :return: 微信服务器响应的 JSON 数据
30 """
31 access_token = self.__conf.access_token if self.__conf is not None else access_token
32 if "params" not in kwargs:
33 kwargs["params"] = {
34 "access_token": access_token
35 }
36 else:
37 kwargs["params"]["access_token"] = access_token
38
39 if isinstance(kwargs.get("data", ""), dict):
40 body = json.dumps(kwargs["data"], ensure_ascii=False)
41 if isinstance(body, six.text_type):
42 body = body.encode('utf8')
43 kwargs["data"] = body
44
45 r = requests.request(
46 method=method,
47 url=url,
48 **kwargs
49 )
50 r.raise_for_status()
51 try:
52 response_json = r.json()
53 except ValueError: # 非 JSON 数据
54 return r
55
56 headimgurl = response_json.get('headimgurl')
57 if headimgurl:
58 response_json['headimgurl'] = headimgurl.replace('\\', '')
59 self._check_official_error(response_json)
60 return response_json
61
62 def get(self, url, access_token=None, **kwargs):
63 """

Callers 2

getMethod · 0.95
postMethod · 0.95

Calls 3

_check_official_errorMethod · 0.95
getMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected