def __init__(self, request_id=None, product=None, env=None): # requestId self.request_id = TeaConverter.to_unicode(request_id) # type: unicode # pop产品 self.product = TeaConverter.to_unicode(product) # type: unicode # 环境 self.env = TeaConverter.to_unicode(env) # type: unicode
def __init__(self, code=None, data=None, request_id=None, success=None): # code self.code = TeaConverter.to_unicode(code) # type: unicode # 产品信息 self.data = data # type: GetAllProductResponseBodyData # Id of the request self.request_id = TeaConverter.to_unicode(request_id) # type: unicode # success self.success = success # type: bool
def recognize_vehicle_parts_advance(self, request, runtime): # Step 0: init client access_key_id = self._credential.get_access_key_id() access_key_secret = self._credential.get_access_key_secret() auth_config = rpc_models.Config(access_key_id=access_key_id, access_key_secret=access_key_secret, type='access_key', endpoint='openplatform.aliyuncs.com', protocol=self._protocol, region_id=self._region_id) auth_client = OpenPlatformClient(auth_config) auth_request = open_platform_models.AuthorizeFileUploadRequest( product='objectdet', region_id=self._region_id) auth_response = open_platform_models.AuthorizeFileUploadResponse() oss_config = oss_models.Config(access_key_secret=access_key_secret, type='access_key', protocol=self._protocol, region_id=self._region_id) oss_client = None file_obj = file_form_models.FileField() oss_header = oss_models.PostObjectRequestHeader() upload_request = oss_models.PostObjectRequest() oss_runtime = ossutil_models.RuntimeOptions() OpenApiUtilClient.convert(runtime, oss_runtime) recognize_vehicle_parts_req = objectdet_20191230_models.RecognizeVehiclePartsRequest( ) OpenApiUtilClient.convert(request, recognize_vehicle_parts_req) auth_response = auth_client.authorize_file_upload_with_options( auth_request, runtime) oss_config.access_key_id = auth_response.access_key_id oss_config.endpoint = OpenApiUtilClient.get_endpoint( auth_response.endpoint, auth_response.use_accelerate, self._endpoint_type) oss_client = OSSClient(oss_config) file_obj = file_form_models.FileField( filename=auth_response.object_key, content=request.image_urlobject, content_type='') oss_header = oss_models.PostObjectRequestHeader( access_key_id=auth_response.access_key_id, policy=auth_response.encoded_policy, signature=auth_response.signature, key=auth_response.object_key, file=file_obj, success_action_status='201') upload_request = oss_models.PostObjectRequest( bucket_name=auth_response.bucket, header=oss_header) oss_client.post_object(upload_request, oss_runtime) recognize_vehicle_parts_req.image_url = 'http://%s.%s/%s' % ( TeaConverter.to_unicode(auth_response.bucket), TeaConverter.to_unicode(auth_response.endpoint), TeaConverter.to_unicode(auth_response.object_key)) recognize_vehicle_parts_resp = self.recognize_vehicle_parts_with_options( recognize_vehicle_parts_req, runtime) return recognize_vehicle_parts_resp
def __init__(self, description=None, domains=None, name_space=None, product=None, type=None): # description self.description = TeaConverter.to_unicode(description) # type: unicode # 域名 self.domains = domains # type: list[unicode] # nameSpace self.name_space = TeaConverter.to_unicode(name_space) # type: unicode # product self.product = TeaConverter.to_unicode(product) # type: unicode # type self.type = TeaConverter.to_unicode(type) # type: unicode
def __init__(self, lang=None, user_client_ip=None, instance_id=None, data_type=None): self.lang = TeaConverter.to_unicode(lang) # type: unicode self.user_client_ip = TeaConverter.to_unicode( user_client_ip) # type: unicode self.instance_id = TeaConverter.to_unicode( instance_id) # type: unicode self.data_type = TeaConverter.to_unicode(data_type) # type: unicode
def __init__(self, status=None, error_message=None, result=None, error_code=None, job_id=None): self.status = TeaConverter.to_unicode(status) # type: unicode self.error_message = TeaConverter.to_unicode( error_message) # type: unicode self.result = TeaConverter.to_unicode(result) # type: unicode self.error_code = TeaConverter.to_unicode(error_code) # type: unicode self.job_id = TeaConverter.to_unicode(job_id) # type: unicode
def __init__(self, type=None, update_timestamp=None, update_time=None, version=None, download_count=None): self.type = TeaConverter.to_unicode(type) # type: unicode self.update_timestamp = update_timestamp # type: long self.update_time = TeaConverter.to_unicode( update_time) # type: unicode self.version = TeaConverter.to_unicode(version) # type: unicode self.download_count = download_count # type: long
def __init__(self, lang=None, user_client_ip=None, instance_id=None, start_date=None, end_date=None): self.lang = TeaConverter.to_unicode(lang) # type: unicode self.user_client_ip = TeaConverter.to_unicode( user_client_ip) # type: unicode self.instance_id = TeaConverter.to_unicode( instance_id) # type: unicode self.start_date = TeaConverter.to_unicode(start_date) # type: unicode self.end_date = TeaConverter.to_unicode(end_date) # type: unicode
def __init__(self, status=None, expire_timestamp=None, expire_time=None, max_qps=None, create_time=None, max_qpd=None, instance_id=None, version_code=None, create_timestamp=None, product_code=None): self.status = TeaConverter.to_unicode(status) # type: unicode self.expire_timestamp = expire_timestamp # type: long self.expire_time = TeaConverter.to_unicode( expire_time) # type: unicode self.max_qps = max_qps # type: long self.create_time = TeaConverter.to_unicode( create_time) # type: unicode self.max_qpd = max_qpd # type: long self.instance_id = TeaConverter.to_unicode( instance_id) # type: unicode self.version_code = TeaConverter.to_unicode( version_code) # type: unicode self.create_timestamp = create_timestamp # type: long self.product_code = TeaConverter.to_unicode( product_code) # type: unicode
def __init__(self, request_id=None, data=None): # Id of the request self.request_id = TeaConverter.to_unicode(request_id) # type: unicode self.data = data # type: SegmentGreenScreenVideoResponseBodyData
class SegmentGreenScreenVideoRequest(TeaModel): def __init__(self, video_url=None, async=None): # A short description of struct self.video_url = TeaConverter.to_unicode(video_url) # type: unicode self. async = async # type: bool
# -*- coding: utf-8 -*- # This file is auto-generated, don't edit it. Thanks. from Tea.model import TeaModel from Tea.converter import TeaConverter class GetAsyncJobResultRequest(TeaModel): def __init__(self, async=None, job_id=None): self. async = async # type: bool self.job_id = TeaConverter.to_unicode(job_id) # type: unicode def validate(self): pass def to_map(self): result = dict() if self. async is not None: result['Async'] = self. async if self.job_id is not None: result['JobId'] = self.job_id return result def from_map(self, m=None): m = m or dict() if m.get('Async') is not None: self. async = m.get('Async') if m.get('JobId') is not None: self.job_id = m.get('JobId') return self
def get_signature_with_options(self, id, headers, runtime): req = open_api_models.OpenApiRequest( headers=headers ) return TeaCore.from_map( pai_plugin_20210325_models.GetSignatureResponse(), self.do_roarequest('GetSignature', '2021-03-25', 'HTTPS', 'GET', 'AK', '/api/v1/signatures/%s' % TeaConverter.to_unicode(id), 'json', req, runtime) )
def __init__(self, access_key_id=None, access_key_secret=None, security_token=None, protocol=None, region_id=None, read_timeout=None, connect_timeout=None, http_proxy=None, https_proxy=None, credential=None, endpoint=None, no_proxy=None, max_idle_conns=None, network=None, user_agent=None, suffix=None, socks_5proxy=None, socks_5net_work=None, endpoint_type=None, open_platform_endpoint=None, type=None): # accesskey id self.access_key_id = TeaConverter.to_unicode( access_key_id) # type: unicode # accesskey secret self.access_key_secret = TeaConverter.to_unicode( access_key_secret) # type: unicode # security token self.security_token = TeaConverter.to_unicode( security_token) # type: unicode # http protocol self.protocol = TeaConverter.to_unicode(protocol) # type: unicode # region id self.region_id = TeaConverter.to_unicode(region_id) # type: unicode # read timeout self.read_timeout = read_timeout # type: int # connect timeout self.connect_timeout = connect_timeout # type: int # http proxy self.http_proxy = TeaConverter.to_unicode(http_proxy) # type: unicode # https proxy self.https_proxy = TeaConverter.to_unicode( https_proxy) # type: unicode # credential self.credential = credential # type: CredentialClient # endpoint self.endpoint = TeaConverter.to_unicode(endpoint) # type: unicode # proxy white list self.no_proxy = TeaConverter.to_unicode(no_proxy) # type: unicode # max idle conns self.max_idle_conns = max_idle_conns # type: int # network for endpoint self.network = TeaConverter.to_unicode(network) # type: unicode # user agent self.user_agent = TeaConverter.to_unicode(user_agent) # type: unicode # suffix for endpoint self.suffix = TeaConverter.to_unicode(suffix) # type: unicode # socks5 proxy self.socks_5proxy = TeaConverter.to_unicode( socks_5proxy) # type: unicode # socks5 network self.socks_5net_work = TeaConverter.to_unicode( socks_5net_work) # type: unicode # endpoint type self.endpoint_type = TeaConverter.to_unicode( endpoint_type) # type: unicode # OpenPlatform endpoint self.open_platform_endpoint = TeaConverter.to_unicode( open_platform_endpoint) # type: unicode # credential type self.type = TeaConverter.to_unicode(type) # type: unicode
def __init__(self, request_id=None, data=None): self.request_id = TeaConverter.to_unicode(request_id) # type: unicode self.data = data # type: SegmentVideoBodyResponseBodyData
def __init__(self, request_id=None, geoip_instances=None): self.request_id = TeaConverter.to_unicode(request_id) # type: unicode self.geoip_instances = geoip_instances # type: DescribeGeoipInstancesResponseBodyGeoipInstances
def __init__(self, request_id=None, download_url=None): self.request_id = TeaConverter.to_unicode(request_id) # type: unicode self.download_url = TeaConverter.to_unicode( download_url) # type: unicode
def __init__(self, request_id=None, data_infos=None): self.request_id = TeaConverter.to_unicode(request_id) # type: unicode self.data_infos = data_infos # type: DescribeGeoipInstanceDataInfosResponseBodyDataInfos
class SegmentVideoBodyRequest(TeaModel): def __init__(self, video_url=None, async=None): self.video_url = TeaConverter.to_unicode(video_url) # type: unicode self. async = async # type: bool
def do_rpcrequest(self, action, version, protocol, method, auth_type, body_type, request, runtime): """ Encapsulate the request and invoke the network @type action: str @param action: api name @type version: str @param version: product version @type protocol: str @param protocol: http or https @type method: str @param method: e.g. GET @type auth_type: str @param auth_type: authorization type e.g. AK @type body_type: str @param body_type: response body type e.g. String @param request: object of OpenApiRequest @param runtime: which controls some details of call api, such as retry times @rtype: dict @return: the response """ request.validate() runtime.validate() _runtime = { 'timeouted': 'retry', 'readTimeout': UtilClient.default_number(runtime.read_timeout, self._read_timeout), 'connectTimeout': UtilClient.default_number(runtime.connect_timeout, self._connect_timeout), 'httpProxy': UtilClient.default_string(runtime.http_proxy, self._http_proxy), 'httpsProxy': UtilClient.default_string(runtime.https_proxy, self._https_proxy), 'noProxy': UtilClient.default_string(runtime.no_proxy, self._no_proxy), 'socks5Proxy': UtilClient.default_string(runtime.socks_5proxy, self._socks_5proxy), 'socks5NetWork': UtilClient.default_string(runtime.socks_5net_work, self._socks_5net_work), 'maxIdleConns': UtilClient.default_number(runtime.max_idle_conns, self._max_idle_conns), 'retry': { 'retryable': runtime.autoretry, 'maxAttempts': UtilClient.default_number(runtime.max_attempts, 3) }, 'backoff': { 'policy': UtilClient.default_string(runtime.backoff_policy, 'no'), 'period': UtilClient.default_number(runtime.backoff_period, 1) }, 'ignoreSSL': runtime.ignore_ssl } _last_request = None _last_exception = None _now = time.time() _retry_times = 0 while TeaCore.allow_retry(_runtime.get('retry'), _retry_times, _now): if _retry_times > 0: _backoff_time = TeaCore.get_backoff_time(_runtime.get('backoff'), _retry_times) if _backoff_time > 0: TeaCore.sleep(_backoff_time) _retry_times = _retry_times + 1 try: _request = TeaRequest() _request.protocol = UtilClient.default_string(self._protocol, protocol) _request.method = method _request.pathname = '/' _request.query = TeaCore.merge({ 'Action': action, 'Format': 'json', 'Version': version, 'Timestamp': OpenApiUtilClient.get_timestamp(), 'SignatureNonce': UtilClient.get_nonce() }, request.query) headers = self.get_rpc_headers() if UtilClient.is_unset(headers): # endpoint is setted in product client _request.headers = { 'host': self._endpoint, 'x-acs-version': version, 'x-acs-action': action, 'user-agent': self.get_user_agent() } else: _request.headers = TeaCore.merge({ 'host': self._endpoint, 'x-acs-version': version, 'x-acs-action': action, 'user-agent': self.get_user_agent() }, headers) if not UtilClient.is_unset(request.body): m = UtilClient.assert_as_map(request.body) tmp = UtilClient.anyify_map_value(OpenApiUtilClient.query(m)) _request.body = UtilClient.to_form_string(tmp) _request.headers['content-type'] = 'application/x-www-form-urlencoded' if not UtilClient.equal_string(auth_type, 'Anonymous'): access_key_id = self.get_access_key_id() access_key_secret = self.get_access_key_secret() security_token = self.get_security_token() if not UtilClient.empty(security_token): _request.query['SecurityToken'] = security_token _request.query['SignatureMethod'] = 'HMAC-SHA1' _request.query['SignatureVersion'] = '1.0' _request.query['AccessKeyId'] = access_key_id t = None if not UtilClient.is_unset(request.body): t = UtilClient.assert_as_map(request.body) signed_param = TeaCore.merge(_request.query, OpenApiUtilClient.query(t)) _request.query['Signature'] = OpenApiUtilClient.get_rpcsignature(signed_param, _request.method, access_key_secret) _last_request = _request _response = TeaCore.do_action(_request, _runtime) if UtilClient.is_4xx(_response.status_code) or UtilClient.is_5xx(_response.status_code): _res = UtilClient.read_as_json(_response.body) err = UtilClient.assert_as_map(_res) request_id = self.default_any(err.get('RequestId'), err.get('requestId')) raise TeaException({ 'code': '%s' % TeaConverter.to_unicode(self.default_any(err.get('Code'), err.get('code'))), 'message': 'code: %s, %s request id: %s' % (TeaConverter.to_unicode(_response.status_code), TeaConverter.to_unicode(self.default_any(err.get('Message'), err.get('message'))), TeaConverter.to_unicode(request_id)), 'data': err }) if UtilClient.equal_string(body_type, 'binary'): resp = { 'body': _response.body, 'headers': _response.headers } return resp elif UtilClient.equal_string(body_type, 'byte'): byt = UtilClient.read_as_bytes(_response.body) return { 'body': byt, 'headers': _response.headers } elif UtilClient.equal_string(body_type, 'string'): str = UtilClient.read_as_string(_response.body) return { 'body': str, 'headers': _response.headers } elif UtilClient.equal_string(body_type, 'json'): obj = UtilClient.read_as_json(_response.body) res = UtilClient.assert_as_map(obj) return { 'body': res, 'headers': _response.headers } elif UtilClient.equal_string(body_type, 'array'): arr = UtilClient.read_as_json(_response.body) return { 'body': arr, 'headers': _response.headers } else: return { 'headers': _response.headers } except Exception as e: if TeaCore.is_retryable(e): _last_exception = e continue raise e raise UnretryableException(_last_request, _last_exception)
def __init__(self, video_url=None): self.video_url = TeaConverter.to_unicode(video_url) # type: unicode
def __init__(self, request_id=None): # Id of the request self.request_id = TeaConverter.to_unicode(request_id) # type: unicode
def __init__(self, request_id=None, data=None): self.request_id = TeaConverter.to_unicode(request_id) # type: unicode self.data = data # type: GetAsyncJobResultResponseBodyData
def do_request(self, params, request, runtime): """ Encapsulate the request and invoke the network @param action: api name @param version: product version @param protocol: http or https @param method: e.g. GET @param auth_type: authorization type e.g. AK @param body_type: response body type e.g. String @param request: object of OpenApiRequest @param runtime: which controls some details of call api, such as retry times @rtype: dict @return: the response """ params.validate() request.validate() runtime.validate() _runtime = { 'timeouted': 'retry', 'readTimeout': UtilClient.default_number(runtime.read_timeout, self._read_timeout), 'connectTimeout': UtilClient.default_number(runtime.connect_timeout, self._connect_timeout), 'httpProxy': UtilClient.default_string(runtime.http_proxy, self._http_proxy), 'httpsProxy': UtilClient.default_string(runtime.https_proxy, self._https_proxy), 'noProxy': UtilClient.default_string(runtime.no_proxy, self._no_proxy), 'socks5Proxy': UtilClient.default_string(runtime.socks_5proxy, self._socks_5proxy), 'socks5NetWork': UtilClient.default_string(runtime.socks_5net_work, self._socks_5net_work), 'maxIdleConns': UtilClient.default_number(runtime.max_idle_conns, self._max_idle_conns), 'retry': { 'retryable': runtime.autoretry, 'maxAttempts': UtilClient.default_number(runtime.max_attempts, 3) }, 'backoff': { 'policy': UtilClient.default_string(runtime.backoff_policy, 'no'), 'period': UtilClient.default_number(runtime.backoff_period, 1) }, 'ignoreSSL': runtime.ignore_ssl } _last_request = None _last_exception = None _now = time.time() _retry_times = 0 while TeaCore.allow_retry(_runtime.get('retry'), _retry_times, _now): if _retry_times > 0: _backoff_time = TeaCore.get_backoff_time(_runtime.get('backoff'), _retry_times) if _backoff_time > 0: TeaCore.sleep(_backoff_time) _retry_times = _retry_times + 1 try: _request = TeaRequest() _request.protocol = UtilClient.default_string(self._protocol, params.protocol) _request.method = params.method _request.pathname = params.pathname _request.query = request.query # endpoint is setted in product client _request.headers = TeaCore.merge({ 'host': self._endpoint, 'x-acs-version': params.version, 'x-acs-action': params.action, 'user-agent': self.get_user_agent(), 'x-acs-date': OpenApiUtilClient.get_timestamp(), 'x-acs-signature-nonce': UtilClient.get_nonce(), 'accept': 'application/json' }, request.headers) if UtilClient.equal_string(params.style, 'RPC'): headers = self.get_rpc_headers() if not UtilClient.is_unset(headers): _request.headers = TeaCore.merge(_request.headers, headers) signature_algorithm = UtilClient.default_string(self._signature_algorithm, 'ACS3-HMAC-SHA256') hashed_request_payload = OpenApiUtilClient.hex_encode(OpenApiUtilClient.hash(UtilClient.to_bytes(''), signature_algorithm)) if not UtilClient.is_unset(request.stream): tmp = UtilClient.read_as_bytes(request.stream) hashed_request_payload = OpenApiUtilClient.hex_encode(OpenApiUtilClient.hash(tmp, signature_algorithm)) _request.body = tmp _request.headers['content-type'] = 'application/octet-stream' else: if not UtilClient.is_unset(request.body): if UtilClient.equal_string(params.req_body_type, 'json'): json_obj = UtilClient.to_jsonstring(request.body) hashed_request_payload = OpenApiUtilClient.hex_encode(OpenApiUtilClient.hash(UtilClient.to_bytes(json_obj), signature_algorithm)) _request.body = json_obj _request.headers['content-type'] = 'application/json; charset=utf-8' else: m = UtilClient.assert_as_map(request.body) form_obj = OpenApiUtilClient.to_form(m) hashed_request_payload = OpenApiUtilClient.hex_encode(OpenApiUtilClient.hash(UtilClient.to_bytes(form_obj), signature_algorithm)) _request.body = form_obj _request.headers['content-type'] = 'application/x-www-form-urlencoded' _request.headers['x-acs-content-sha256'] = hashed_request_payload if not UtilClient.equal_string(params.auth_type, 'Anonymous'): auth_type = self.get_type() if UtilClient.equal_string(auth_type, 'bearer'): bearer_token = self.get_bearer_token() _request.headers['x-acs-bearer-token'] = bearer_token else: access_key_id = self.get_access_key_id() access_key_secret = self.get_access_key_secret() security_token = self.get_security_token() if not UtilClient.empty(security_token): _request.headers['x-acs-accesskey-id'] = access_key_id _request.headers['x-acs-security-token'] = security_token _request.headers['Authorization'] = OpenApiUtilClient.get_authorization(_request, signature_algorithm, hashed_request_payload, access_key_id, access_key_secret) _last_request = _request _response = TeaCore.do_action(_request, _runtime) if UtilClient.is_4xx(_response.status_code) or UtilClient.is_5xx(_response.status_code): err = {} if not UtilClient.is_unset(_response.headers.get('content-type')) and UtilClient.equal_string(_response.headers.get('content-type'), 'text/xml;charset=utf-8'): _str = UtilClient.read_as_string(_response.body) resp_map = XMLClient.parse_xml(_str, None) err = UtilClient.assert_as_map(resp_map.get('Error')) else: _res = UtilClient.read_as_json(_response.body) err = UtilClient.assert_as_map(_res) err['statusCode'] = _response.status_code raise TeaException({ 'code': '%s' % TeaConverter.to_unicode(self.default_any(err.get('Code'), err.get('code'))), 'message': 'code: %s, %s request id: %s' % (TeaConverter.to_unicode(_response.status_code), TeaConverter.to_unicode(self.default_any(err.get('Message'), err.get('message'))), TeaConverter.to_unicode(self.default_any(err.get('RequestId'), err.get('requestId')))), 'data': err }) if UtilClient.equal_string(params.body_type, 'binary'): resp = { 'body': _response.body, 'headers': _response.headers, 'statusCode': _response.status_code } return resp elif UtilClient.equal_string(params.body_type, 'byte'): byt = UtilClient.read_as_bytes(_response.body) return { 'body': byt, 'headers': _response.headers, 'statusCode': _response.status_code } elif UtilClient.equal_string(params.body_type, 'string'): str = UtilClient.read_as_string(_response.body) return { 'body': str, 'headers': _response.headers, 'statusCode': _response.status_code } elif UtilClient.equal_string(params.body_type, 'json'): obj = UtilClient.read_as_json(_response.body) res = UtilClient.assert_as_map(obj) return { 'body': res, 'headers': _response.headers, 'statusCode': _response.status_code } elif UtilClient.equal_string(params.body_type, 'array'): arr = UtilClient.read_as_json(_response.body) return { 'body': arr, 'headers': _response.headers, 'statusCode': _response.status_code } else: return { 'headers': _response.headers, 'statusCode': _response.status_code } except Exception as e: if TeaCore.is_retryable(e): _last_exception = e continue raise e raise UnretryableException(_last_request, _last_exception)
def __init__(self, request_id=None, statistics=None): self.request_id = TeaConverter.to_unicode(request_id) # type: unicode self.statistics = statistics # type: DescribeGeoipInstanceStatisticsResponseBodyStatistics
def delete_template_with_options(self, id, headers, runtime): req = open_api_models.OpenApiRequest( headers=headers ) return TeaCore.from_map( pai_plugin_20210325_models.DeleteTemplateResponse(), self.do_roarequest('DeleteTemplate', '2021-03-25', 'HTTPS', 'DELETE', 'AK', '/api/v1/templates/%s' % TeaConverter.to_unicode(id), 'json', req, runtime) )
def __init__(self, lang=None, user_client_ip=None, ip=None): self.lang = TeaConverter.to_unicode(lang) # type: unicode self.user_client_ip = TeaConverter.to_unicode( user_client_ip) # type: unicode self.ip = TeaConverter.to_unicode(ip) # type: unicode
def __init__(self, province_en=None, request_id=None, city_en=None, ip=None, isp=None, latitude=None, city=None, county=None, longitude=None, country_en=None, province=None, country=None, country_code=None): self.province_en = TeaConverter.to_unicode( province_en) # type: unicode self.request_id = TeaConverter.to_unicode(request_id) # type: unicode self.city_en = TeaConverter.to_unicode(city_en) # type: unicode self.ip = TeaConverter.to_unicode(ip) # type: unicode self.isp = TeaConverter.to_unicode(isp) # type: unicode self.latitude = TeaConverter.to_unicode(latitude) # type: unicode self.city = TeaConverter.to_unicode(city) # type: unicode self.county = TeaConverter.to_unicode(county) # type: unicode self.longitude = TeaConverter.to_unicode(longitude) # type: unicode self.country_en = TeaConverter.to_unicode(country_en) # type: unicode self.province = TeaConverter.to_unicode(province) # type: unicode self.country = TeaConverter.to_unicode(country) # type: unicode self.country_code = TeaConverter.to_unicode( country_code) # type: unicode
def detect_face_attributes_advance(self, request, runtime): # Step 0: init client access_key_id = self._credential.get_access_key_id() access_key_secret = self._credential.get_access_key_secret() security_token = self._credential.get_security_token() credential_type = self._credential.get_type() open_platform_endpoint = self._open_platform_endpoint if UtilClient.is_unset(open_platform_endpoint): open_platform_endpoint = 'openplatform.aliyuncs.com' if UtilClient.is_unset(credential_type): credential_type = 'access_key' auth_config = rpc_models.Config(access_key_id=access_key_id, access_key_secret=access_key_secret, security_token=security_token, type=credential_type, endpoint=open_platform_endpoint, protocol=self._protocol, region_id=self._region_id) auth_client = OpenPlatformClient(auth_config) auth_request = open_platform_models.AuthorizeFileUploadRequest( product='Cloudauth', region_id=self._region_id) auth_response = open_platform_models.AuthorizeFileUploadResponse() oss_config = oss_models.Config(access_key_secret=access_key_secret, type='access_key', protocol=self._protocol, region_id=self._region_id) oss_client = None file_obj = file_form_models.FileField() oss_header = oss_models.PostObjectRequestHeader() upload_request = oss_models.PostObjectRequest() oss_runtime = ossutil_models.RuntimeOptions() OpenApiUtilClient.convert(runtime, oss_runtime) detect_face_attributes_req = cloudauth_20201112_models.DetectFaceAttributesRequest( ) OpenApiUtilClient.convert(request, detect_face_attributes_req) if not UtilClient.is_unset(request.image_file_object): auth_response = auth_client.authorize_file_upload_with_options( auth_request, runtime) oss_config.access_key_id = auth_response.access_key_id oss_config.endpoint = OpenApiUtilClient.get_endpoint( auth_response.endpoint, auth_response.use_accelerate, self._endpoint_type) oss_client = OSSClient(oss_config) file_obj = file_form_models.FileField( filename=auth_response.object_key, content=request.image_file_object, content_type='') oss_header = oss_models.PostObjectRequestHeader( access_key_id=auth_response.access_key_id, policy=auth_response.encoded_policy, signature=auth_response.signature, key=auth_response.object_key, file=file_obj, success_action_status='201') upload_request = oss_models.PostObjectRequest( bucket_name=auth_response.bucket, header=oss_header) oss_client.post_object(upload_request, oss_runtime) detect_face_attributes_req.image_file = 'http://%s.%s/%s' % ( TeaConverter.to_unicode(auth_response.bucket), TeaConverter.to_unicode(auth_response.endpoint), TeaConverter.to_unicode(auth_response.object_key)) detect_face_attributes_resp = self.detect_face_attributes_with_options( detect_face_attributes_req, runtime) return detect_face_attributes_resp
def do_request(self, action, protocol, method, version, auth_type, query, body, runtime): """ Encapsulate the request and invoke the network @type action: unicode @param action: api name @type protocol: unicode @param protocol: http or https @type method: unicode @param method: e.g. GET @type version: unicode @param version: product version @type auth_type: unicode @param auth_type: when authType is Anonymous, the signature will not be calculate @param pathname: pathname of every api @type query: dict @param query: which contains request params @type body: dict @param body: content of request @param runtime: which controls some details of call api, such as retry times @rtype: dict @return: the response """ runtime.validate() _runtime = { 'timeouted': 'retry', 'readTimeout': UtilClient.default_number(runtime.read_timeout, self._read_timeout), 'connectTimeout': UtilClient.default_number(runtime.connect_timeout, self._connect_timeout), 'httpProxy': UtilClient.default_string(runtime.http_proxy, self._http_proxy), 'httpsProxy': UtilClient.default_string(runtime.https_proxy, self._https_proxy), 'noProxy': UtilClient.default_string(runtime.no_proxy, self._no_proxy), 'maxIdleConns': UtilClient.default_number(runtime.max_idle_conns, self._max_idle_conns), 'retry': { 'retryable': runtime.autoretry, 'maxAttempts': UtilClient.default_number(runtime.max_attempts, 3) }, 'backoff': { 'policy': UtilClient.default_string(runtime.backoff_policy, 'no'), 'period': UtilClient.default_number(runtime.backoff_period, 1) }, 'ignoreSSL': runtime.ignore_ssl } _last_request = None _last_exception = None _now = time.time() _retry_times = 0 while TeaCore.allow_retry(_runtime.get('retry'), _retry_times, _now): if _retry_times > 0: _backoff_time = TeaCore.get_backoff_time(_runtime.get('backoff'), _retry_times) if _backoff_time > 0: TeaCore.sleep(_backoff_time) _retry_times = _retry_times + 1 try: _request = TeaRequest() _request.protocol = UtilClient.default_string(self._protocol, protocol) _request.method = method _request.pathname = '/' _request.query = RPCUtilClient.query(TeaCore.merge({ 'Action': action, 'Format': 'json', 'Timestamp': RPCUtilClient.get_timestamp(), 'Version': version, 'SignatureNonce': UtilClient.get_nonce() }, query)) # endpoint is setted in product client _request.headers = { 'x-acs-version': version, 'x-acs-action': action, 'host': self._endpoint, 'user-agent': self.get_user_agent() } if not UtilClient.is_unset(body): tmp = UtilClient.anyify_map_value(RPCUtilClient.query(body)) _request.body = UtilClient.to_form_string(tmp) _request.headers['content-type'] = 'application/x-www-form-urlencoded' if not UtilClient.equal_string(auth_type, 'Anonymous'): access_key_id = self.get_access_key_id() access_key_secret = self.get_access_key_secret() security_token = self.get_security_token() if not UtilClient.empty(security_token): _request.query['SecurityToken'] = security_token _request.query['SignatureMethod'] = 'HMAC-SHA1' _request.query['SignatureVersion'] = '1.0' _request.query['AccessKeyId'] = access_key_id signed_param = TeaCore.merge(_request.query, RPCUtilClient.query(body)) _request.query['Signature'] = RPCUtilClient.get_signature_v1(signed_param, _request.method, access_key_secret) _last_request = _request _response = TeaCore.do_action(_request, _runtime) obj = UtilClient.read_as_json(_response.body) res = UtilClient.assert_as_map(obj) if UtilClient.is_4xx(_response.status_code) or UtilClient.is_5xx(_response.status_code): raise TeaException({ 'code': '%s' % TeaConverter.to_unicode(self.default_any(res.get('Code'), res.get('code'))), 'message': 'code: %s, %s request id: %s' % (TeaConverter.to_unicode(_response.status_code), TeaConverter.to_unicode(self.default_any(res.get('Message'), res.get('message'))), TeaConverter.to_unicode(self.default_any(res.get('RequestId'), res.get('requestId')))), 'data': res }) return res except Exception as e: if TeaCore.is_retryable(e): _last_exception = e continue raise e raise UnretryableException(_last_request, _last_exception)