11# -*- coding: utf-8 -*-
22# This file is auto-generated, don't edit it. Thanks.
3+ import time
4+
35from Tea .request import TeaRequest
4- from Tea .exceptions import TeaException
6+ from Tea .exceptions import TeaException , UnretryableException
57from Tea .core import TeaCore
68from typing import Dict
79
810from alibabacloud_tea_openapi .client import Client as OpenApiClient
911from alibabacloud_tea_openapi import models as open_api_models
12+ from alibabacloud_tea_util import models as util_models
1013from alibabacloud_tea_util .client import Client as UtilClient
1114from alibabacloud_tea_fileform .client import Client as FileFormClient
1215from alibabacloud_tea_xml .client import Client as XMLClient
1316from alibabacloud_endpoint_util .client import Client as EndpointUtilClient
1417from alibabacloud_cloudauth_intl20220809 import models as cloudauth_intl_20220809_models
15- from alibabacloud_tea_util import models as util_models
1618from alibabacloud_openapi_util .client import Client as OpenApiUtilClient
1719from alibabacloud_tea_fileform import models as file_form_models
1820
@@ -34,77 +36,163 @@ def _post_ossobject(
3436 self ,
3537 bucket_name : str ,
3638 data : dict ,
39+ runtime : util_models .RuntimeOptions ,
3740 ) -> dict :
38- _request = TeaRequest ()
39- form = UtilClient .assert_as_map (data )
40- boundary = FileFormClient .get_boundary ()
41- host = UtilClient .assert_as_string (form .get ('host' ))
42- _request .protocol = 'HTTPS'
43- _request .method = 'POST'
44- _request .pathname = f'/'
45- _request .headers = {
46- 'host' : host ,
47- 'date' : UtilClient .get_date_utcstring (),
48- 'user-agent' : UtilClient .get_user_agent ('' )
41+ runtime .validate ()
42+ _runtime = {
43+ 'timeouted' : 'retry' ,
44+ 'key' : UtilClient .default_string (runtime .key , self ._key ),
45+ 'cert' : UtilClient .default_string (runtime .cert , self ._cert ),
46+ 'ca' : UtilClient .default_string (runtime .ca , self ._ca ),
47+ 'readTimeout' : UtilClient .default_number (runtime .read_timeout , self ._read_timeout ),
48+ 'connectTimeout' : UtilClient .default_number (runtime .connect_timeout , self ._connect_timeout ),
49+ 'httpProxy' : UtilClient .default_string (runtime .http_proxy , self ._http_proxy ),
50+ 'httpsProxy' : UtilClient .default_string (runtime .https_proxy , self ._https_proxy ),
51+ 'noProxy' : UtilClient .default_string (runtime .no_proxy , self ._no_proxy ),
52+ 'socks5Proxy' : UtilClient .default_string (runtime .socks_5proxy , self ._socks_5proxy ),
53+ 'socks5NetWork' : UtilClient .default_string (runtime .socks_5net_work , self ._socks_5net_work ),
54+ 'maxIdleConns' : UtilClient .default_number (runtime .max_idle_conns , self ._max_idle_conns ),
55+ 'retry' : {
56+ 'retryable' : runtime .autoretry ,
57+ 'maxAttempts' : UtilClient .default_number (runtime .max_attempts , 3 )
58+ },
59+ 'backoff' : {
60+ 'policy' : UtilClient .default_string (runtime .backoff_policy , 'no' ),
61+ 'period' : UtilClient .default_number (runtime .backoff_period , 1 )
62+ },
63+ 'ignoreSSL' : OpenApiClient .default_any (runtime .ignore_ssl , False ),
64+ 'tlsMinVersion' : self ._tls_min_version
4965 }
50- _request .headers ['content-type' ] = f'multipart/form-data; boundary={ boundary } '
51- _request .body = FileFormClient .to_file_form (form , boundary )
52- _last_request = _request
53- _response = TeaCore .do_action (_request )
54- resp_map = None
55- body_str = UtilClient .read_as_string (_response .body )
56- if UtilClient .is_4xx (_response .status_code ) or UtilClient .is_5xx (_response .status_code ):
57- resp_map = XMLClient .parse_xml (body_str , None )
58- err = UtilClient .assert_as_map (resp_map .get ('Error' ))
59- raise TeaException ({
60- 'code' : err .get ('Code' ),
61- 'message' : err .get ('Message' ),
62- 'data' : {
63- 'httpCode' : _response .status_code ,
64- 'requestId' : err .get ('RequestId' ),
65- 'hostId' : err .get ('HostId' )
66+ _last_request = None
67+ _last_exception = None
68+ _now = time .time ()
69+ _retry_times = 0
70+ while TeaCore .allow_retry (_runtime .get ('retry' ), _retry_times , _now ):
71+ if _retry_times > 0 :
72+ _backoff_time = TeaCore .get_backoff_time (_runtime .get ('backoff' ), _retry_times )
73+ if _backoff_time > 0 :
74+ TeaCore .sleep (_backoff_time )
75+ _retry_times = _retry_times + 1
76+ try :
77+ _request = TeaRequest ()
78+ form = UtilClient .assert_as_map (data )
79+ boundary = FileFormClient .get_boundary ()
80+ host = UtilClient .assert_as_string (form .get ('host' ))
81+ _request .protocol = 'HTTPS'
82+ _request .method = 'POST'
83+ _request .pathname = f'/'
84+ _request .headers = {
85+ 'host' : host ,
86+ 'date' : UtilClient .get_date_utcstring (),
87+ 'user-agent' : UtilClient .get_user_agent ('' )
6688 }
67- })
68- resp_map = XMLClient .parse_xml (body_str , None )
69- return TeaCore .merge (resp_map )
89+ _request .headers ['content-type' ] = f'multipart/form-data; boundary={ boundary } '
90+ _request .body = FileFormClient .to_file_form (form , boundary )
91+ _last_request = _request
92+ _response = TeaCore .do_action (_request , _runtime )
93+ resp_map = None
94+ body_str = UtilClient .read_as_string (_response .body )
95+ if UtilClient .is_4xx (_response .status_code ) or UtilClient .is_5xx (_response .status_code ):
96+ resp_map = XMLClient .parse_xml (body_str , None )
97+ err = UtilClient .assert_as_map (resp_map .get ('Error' ))
98+ raise TeaException ({
99+ 'code' : err .get ('Code' ),
100+ 'message' : err .get ('Message' ),
101+ 'data' : {
102+ 'httpCode' : _response .status_code ,
103+ 'requestId' : err .get ('RequestId' ),
104+ 'hostId' : err .get ('HostId' )
105+ }
106+ })
107+ resp_map = XMLClient .parse_xml (body_str , None )
108+ return TeaCore .merge (resp_map )
109+ except Exception as e :
110+ if TeaCore .is_retryable (e ):
111+ _last_exception = e
112+ continue
113+ raise e
114+ raise UnretryableException (_last_request , _last_exception )
70115
71116 async def _post_ossobject_async (
72117 self ,
73118 bucket_name : str ,
74119 data : dict ,
120+ runtime : util_models .RuntimeOptions ,
75121 ) -> dict :
76- _request = TeaRequest ()
77- form = UtilClient .assert_as_map (data )
78- boundary = FileFormClient .get_boundary ()
79- host = UtilClient .assert_as_string (form .get ('host' ))
80- _request .protocol = 'HTTPS'
81- _request .method = 'POST'
82- _request .pathname = f'/'
83- _request .headers = {
84- 'host' : host ,
85- 'date' : UtilClient .get_date_utcstring (),
86- 'user-agent' : UtilClient .get_user_agent ('' )
122+ runtime .validate ()
123+ _runtime = {
124+ 'timeouted' : 'retry' ,
125+ 'key' : UtilClient .default_string (runtime .key , self ._key ),
126+ 'cert' : UtilClient .default_string (runtime .cert , self ._cert ),
127+ 'ca' : UtilClient .default_string (runtime .ca , self ._ca ),
128+ 'readTimeout' : UtilClient .default_number (runtime .read_timeout , self ._read_timeout ),
129+ 'connectTimeout' : UtilClient .default_number (runtime .connect_timeout , self ._connect_timeout ),
130+ 'httpProxy' : UtilClient .default_string (runtime .http_proxy , self ._http_proxy ),
131+ 'httpsProxy' : UtilClient .default_string (runtime .https_proxy , self ._https_proxy ),
132+ 'noProxy' : UtilClient .default_string (runtime .no_proxy , self ._no_proxy ),
133+ 'socks5Proxy' : UtilClient .default_string (runtime .socks_5proxy , self ._socks_5proxy ),
134+ 'socks5NetWork' : UtilClient .default_string (runtime .socks_5net_work , self ._socks_5net_work ),
135+ 'maxIdleConns' : UtilClient .default_number (runtime .max_idle_conns , self ._max_idle_conns ),
136+ 'retry' : {
137+ 'retryable' : runtime .autoretry ,
138+ 'maxAttempts' : UtilClient .default_number (runtime .max_attempts , 3 )
139+ },
140+ 'backoff' : {
141+ 'policy' : UtilClient .default_string (runtime .backoff_policy , 'no' ),
142+ 'period' : UtilClient .default_number (runtime .backoff_period , 1 )
143+ },
144+ 'ignoreSSL' : OpenApiClient .default_any (runtime .ignore_ssl , False ),
145+ 'tlsMinVersion' : self ._tls_min_version
87146 }
88- _request .headers ['content-type' ] = f'multipart/form-data; boundary={ boundary } '
89- _request .body = FileFormClient .to_file_form (form , boundary )
90- _last_request = _request
91- _response = await TeaCore .async_do_action (_request )
92- resp_map = None
93- body_str = await UtilClient .read_as_string_async (_response .body )
94- if UtilClient .is_4xx (_response .status_code ) or UtilClient .is_5xx (_response .status_code ):
95- resp_map = XMLClient .parse_xml (body_str , None )
96- err = UtilClient .assert_as_map (resp_map .get ('Error' ))
97- raise TeaException ({
98- 'code' : err .get ('Code' ),
99- 'message' : err .get ('Message' ),
100- 'data' : {
101- 'httpCode' : _response .status_code ,
102- 'requestId' : err .get ('RequestId' ),
103- 'hostId' : err .get ('HostId' )
147+ _last_request = None
148+ _last_exception = None
149+ _now = time .time ()
150+ _retry_times = 0
151+ while TeaCore .allow_retry (_runtime .get ('retry' ), _retry_times , _now ):
152+ if _retry_times > 0 :
153+ _backoff_time = TeaCore .get_backoff_time (_runtime .get ('backoff' ), _retry_times )
154+ if _backoff_time > 0 :
155+ TeaCore .sleep (_backoff_time )
156+ _retry_times = _retry_times + 1
157+ try :
158+ _request = TeaRequest ()
159+ form = UtilClient .assert_as_map (data )
160+ boundary = FileFormClient .get_boundary ()
161+ host = UtilClient .assert_as_string (form .get ('host' ))
162+ _request .protocol = 'HTTPS'
163+ _request .method = 'POST'
164+ _request .pathname = f'/'
165+ _request .headers = {
166+ 'host' : host ,
167+ 'date' : UtilClient .get_date_utcstring (),
168+ 'user-agent' : UtilClient .get_user_agent ('' )
104169 }
105- })
106- resp_map = XMLClient .parse_xml (body_str , None )
107- return TeaCore .merge (resp_map )
170+ _request .headers ['content-type' ] = f'multipart/form-data; boundary={ boundary } '
171+ _request .body = FileFormClient .to_file_form (form , boundary )
172+ _last_request = _request
173+ _response = await TeaCore .async_do_action (_request , _runtime )
174+ resp_map = None
175+ body_str = await UtilClient .read_as_string_async (_response .body )
176+ if UtilClient .is_4xx (_response .status_code ) or UtilClient .is_5xx (_response .status_code ):
177+ resp_map = XMLClient .parse_xml (body_str , None )
178+ err = UtilClient .assert_as_map (resp_map .get ('Error' ))
179+ raise TeaException ({
180+ 'code' : err .get ('Code' ),
181+ 'message' : err .get ('Message' ),
182+ 'data' : {
183+ 'httpCode' : _response .status_code ,
184+ 'requestId' : err .get ('RequestId' ),
185+ 'hostId' : err .get ('HostId' )
186+ }
187+ })
188+ resp_map = XMLClient .parse_xml (body_str , None )
189+ return TeaCore .merge (resp_map )
190+ except Exception as e :
191+ if TeaCore .is_retryable (e ):
192+ _last_exception = e
193+ continue
194+ raise e
195+ raise UnretryableException (_last_request , _last_exception )
108196
109197 def get_endpoint (
110198 self ,
@@ -1560,7 +1648,7 @@ def credential_verify_intl_advance(
15601648 'file' : file_obj ,
15611649 'success_action_status' : '201'
15621650 }
1563- self ._post_ossobject (auth_response_body .get ('Bucket' ), oss_header )
1651+ self ._post_ossobject (auth_response_body .get ('Bucket' ), oss_header , runtime )
15641652 credential_verify_intl_req .image_file = f"http://{ auth_response_body .get ('Bucket' )} .{ auth_response_body .get ('Endpoint' )} /{ auth_response_body .get ('ObjectKey' )} "
15651653 credential_verify_intl_resp = self .credential_verify_intl_with_options (credential_verify_intl_req , runtime )
15661654 return credential_verify_intl_resp
@@ -1643,7 +1731,7 @@ async def credential_verify_intl_advance_async(
16431731 'file' : file_obj ,
16441732 'success_action_status' : '201'
16451733 }
1646- await self ._post_ossobject_async (auth_response_body .get ('Bucket' ), oss_header )
1734+ await self ._post_ossobject_async (auth_response_body .get ('Bucket' ), oss_header , runtime )
16471735 credential_verify_intl_req .image_file = f"http://{ auth_response_body .get ('Bucket' )} .{ auth_response_body .get ('Endpoint' )} /{ auth_response_body .get ('ObjectKey' )} "
16481736 credential_verify_intl_resp = await self .credential_verify_intl_with_options_async (credential_verify_intl_req , runtime )
16491737 return credential_verify_intl_resp
@@ -1982,7 +2070,7 @@ def deepfake_detect_intl_stream_advance(
19822070 'file' : file_obj ,
19832071 'success_action_status' : '201'
19842072 }
1985- self ._post_ossobject (auth_response_body .get ('Bucket' ), oss_header )
2073+ self ._post_ossobject (auth_response_body .get ('Bucket' ), oss_header , runtime )
19862074 deepfake_detect_intl_stream_req .face_file = f"http://{ auth_response_body .get ('Bucket' )} .{ auth_response_body .get ('Endpoint' )} /{ auth_response_body .get ('ObjectKey' )} "
19872075 deepfake_detect_intl_stream_resp = self .deepfake_detect_intl_stream_with_options (deepfake_detect_intl_stream_req , runtime )
19882076 return deepfake_detect_intl_stream_resp
@@ -2065,7 +2153,7 @@ async def deepfake_detect_intl_stream_advance_async(
20652153 'file' : file_obj ,
20662154 'success_action_status' : '201'
20672155 }
2068- await self ._post_ossobject_async (auth_response_body .get ('Bucket' ), oss_header )
2156+ await self ._post_ossobject_async (auth_response_body .get ('Bucket' ), oss_header , runtime )
20692157 deepfake_detect_intl_stream_req .face_file = f"http://{ auth_response_body .get ('Bucket' )} .{ auth_response_body .get ('Endpoint' )} /{ auth_response_body .get ('ObjectKey' )} "
20702158 deepfake_detect_intl_stream_resp = await self .deepfake_detect_intl_stream_with_options_async (deepfake_detect_intl_stream_req , runtime )
20712159 return deepfake_detect_intl_stream_resp
@@ -2523,6 +2611,8 @@ def doc_ocr_max_with_options(
25232611 if not UtilClient .is_unset (request .ocr_value_standard ):
25242612 query ['OcrValueStandard' ] = request .ocr_value_standard
25252613 body = {}
2614+ if not UtilClient .is_unset (request .authorize ):
2615+ body ['Authorize' ] = request .authorize
25262616 if not UtilClient .is_unset (request .doc_page ):
25272617 body ['DocPage' ] = request .doc_page
25282618 if not UtilClient .is_unset (request .doc_type ):
@@ -2586,6 +2676,8 @@ async def doc_ocr_max_with_options_async(
25862676 if not UtilClient .is_unset (request .ocr_value_standard ):
25872677 query ['OcrValueStandard' ] = request .ocr_value_standard
25882678 body = {}
2679+ if not UtilClient .is_unset (request .authorize ):
2680+ body ['Authorize' ] = request .authorize
25892681 if not UtilClient .is_unset (request .doc_page ):
25902682 body ['DocPage' ] = request .doc_page
25912683 if not UtilClient .is_unset (request .doc_type ):
0 commit comments