text
stringlengths
0
828
raise DbQueryError(decoded_resp['error'])
raise UnexpectedError()
else:
process_meta_api_error_code(resp.status_code, request, resp.text)
except (requests.exceptions.ConnectionError, ConnectionError, TimeoutError) as e:
self.log.warning('META API Connection Error. Sleep...', {""e"": e})
time.sleep(15)
except Exception as e:
if 'Служба частично или полностью недоступна' in str(e):
self.log.warning('META API Connection Error. Sleep...', {""e"": e})
time.sleep(15)
else:
raise e
raise ServerError(request)"
4806,"def native_api_call(self, service, method, data, options, multipart_form=False, multipart_form_data=None, stream=False, http_path=""/api/meta/v1/"", http_method='POST',
get_params=None, connect_timeout_sec=60):
""""""
:type app: metasdk.MetaApp
:rtype: requests.Response
""""""
if get_params is None:
get_params = {}
if 'self' in data:
# может не быть, если вызывается напрямую из кода,
# а не из прослоек типа DbQueryService
data.pop(""self"")
if options:
data.update(options)
_headers = dict(self.__default_headers)
if self.auth_user_id:
_headers['X-META-AuthUserID'] = str(self.auth_user_id)
request = {
""url"": self.meta_url + http_path + service + ""/"" + method,
""timeout"": (connect_timeout_sec, 1800),
""stream"": stream,
""params"": get_params,
}
if multipart_form:
if multipart_form_data:
request['files'] = multipart_form_data
request['data'] = data
_headers.pop('content-type', None)
else:
request['data'] = json.dumps(data)
request['headers'] = _headers
for _try_idx in range(20):
try:
resp = requests.request(http_method, **request)
if resp.status_code == 200:
return resp
else:
process_meta_api_error_code(resp.status_code, request, resp.text)
except (requests.exceptions.ConnectionError, ConnectionError, TimeoutError) as e:
self.log.warning('META API Connection Error. Sleep...', {""e"": e})
time.sleep(15)
except Exception as e:
if 'Служба частично или полностью недоступна' in str(e):
self.log.warning('META API Service Temporarily Unavailable. Sleep...', {""e"": e})
time.sleep(15)
else:
raise e
raise ServerError(request)"
4807,"async def get_json(self, url, timeout=30, astext=False, exceptions=False):
""""""Get URL and parse JSON from text.""""""
try:
with async_timeout.timeout(timeout):
res = await self._aio_session.get(url)
if res.status != 200:
_LOGGER.error(""QSUSB returned %s [%s]"", res.status, url)
return None
res_text = await res.text()
except (aiohttp.client_exceptions.ClientError,
asyncio.TimeoutError) as exc:
if exceptions:
raise exc
return None
if astext:
return res_text
try:
return json.loads(res_text)
except json.decoder.JSONDecodeError:
if res_text.strip("" "") == """":
return None
_LOGGER.error(""Could not decode %s [%s]"", res_text, url)"
4808,"def stop(self):
""""""Stop listening.""""""
self._running = False
if self._sleep_task:
self._sleep_task.cancel()
self._sleep_task = None"