MCPcopy
hub / github.com/wechatpy/wechatpy / _request

Method _request

wechatpy/oauth.py:46–88  ·  view source on GitHub ↗
(self, method, url_or_endpoint, **kwargs)

Source from the content-addressed store, hash-verified

44 self._http = requests.Session()
45
46 def _request(self, method, url_or_endpoint, **kwargs):
47 if not url_or_endpoint.startswith(('http://', 'https://')):
48 url = '{base}{endpoint}'.format(
49 base=self.API_BASE_URL,
50 endpoint=url_or_endpoint
51 )
52 else:
53 url = url_or_endpoint
54
55 if isinstance(kwargs.get('data', ''), dict):
56 body = json.dumps(kwargs['data'], ensure_ascii=False)
57 body = body.encode('utf-8')
58 kwargs['data'] = body
59
60 res = self._http.request(
61 method=method,
62 url=url,
63 **kwargs
64 )
65 try:
66 res.raise_for_status()
67 except requests.RequestException as reqe:
68 raise WeChatOAuthException(
69 errcode=None,
70 errmsg=None,
71 client=self,
72 request=reqe.request,
73 response=reqe.response
74 )
75 result = json.loads(res.content.decode('utf-8', 'ignore'), strict=False)
76
77 if 'errcode' in result and result['errcode'] != 0:
78 errcode = result['errcode']
79 errmsg = result['errmsg']
80 raise WeChatOAuthException(
81 errcode,
82 errmsg,
83 client=self,
84 request=res.request,
85 response=res
86 )
87
88 return result
89
90 def _get(self, url, **kwargs):
91 return self._request(

Callers 1

_getMethod · 0.95

Calls 4

encodeMethod · 0.80
decodeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected