예제 #1
0
 def upload_merchant_image_ex(
     self,
     request: industry_models.UploadMerchantImageRequest,
     headers: Dict[str, str],
     runtime: util_models.RuntimeOptions,
 ) -> industry_models.UploadMerchantImageResponse:
     """
     Description: 行业商家图片上传
     Summary: 行业商家图片上传
     """
     if not UtilClient.is_unset(request.file_object):
         upload_req = industry_models.CreateAntcloudGatewayxFileUploadRequest(
             auth_token=request.auth_token,
             api_code='antcloud.industry.merchant.image.upload',
             file_name=request.file_object_name
         )
         upload_resp = self.create_antcloud_gatewayx_file_upload_ex(upload_req, headers, runtime)
         if not AntchainUtils.is_success(upload_resp.result_code, 'ok'):
             upload_merchant_image_response = industry_models.UploadMerchantImageResponse(
                 req_msg_id=upload_resp.req_msg_id,
                 result_code=upload_resp.result_code,
                 result_msg=upload_resp.result_msg
             )
             return upload_merchant_image_response
         upload_headers = AntchainUtils.parse_upload_headers(upload_resp.upload_headers)
         AntchainUtils.put_object(request.file_object, upload_headers, upload_resp.upload_url)
         request.file_id = upload_resp.file_id
     UtilClient.validate_model(request)
     return industry_models.UploadMerchantImageResponse().from_map(
         self.do_request('1.0', 'antcloud.industry.merchant.image.upload', 'HTTPS', 'POST', f'/gateway.do', TeaCore.to_map(request), headers, runtime)
     )
예제 #2
0
 def echo_gateway_check_ex(
     self,
     request: demo_models.EchoGatewayCheckRequest,
     headers: Dict[str, str],
     runtime: util_models.RuntimeOptions,
 ) -> demo_models.EchoGatewayCheckResponse:
     """
     Description: Demo接口,返回当输入的值
     Summary: 返回输入值
     """
     if not UtilClient.is_unset(request.file_object):
         upload_req = demo_models.CreateAntcloudGatewayxFileUploadRequest(
             api_code='demo.gateway.check.echo')
         upload_resp = self.create_antcloud_gatewayx_file_upload_ex(
             upload_req, headers, runtime)
         if not AntchainUtils.is_success(upload_resp.result_code, 'OK'):
             echo_gateway_check_response = demo_models.EchoGatewayCheckResponse(
                 req_msg_id=upload_resp.req_msg_id,
                 result_code=upload_resp.result_code,
                 result_msg=upload_resp.result_msg)
             return echo_gateway_check_response
         upload_headers = AntchainUtils.parse_upload_headers(
             upload_resp.upload_headers)
         AntchainUtils.put_object(request.file_object, upload_headers,
                                  upload_resp.upload_url)
         request.file_id = upload_resp.file_id
     UtilClient.validate_model(request)
     return demo_models.EchoGatewayCheckResponse().from_map(
         self.do_request('1.0', 'demo.gateway.check.echo',
                         'HTTPS', 'POST', f'/gateway.do',
                         TeaCore.to_map(request), headers, runtime))
    def test_put_object(self):
        url = 'http://127.0.0.1:8888'
        with open('test.txt', 'rb') as f:
            AntchainUtils.put_object(f, {'expected': 'success'}, url)

        with open('test.txt', 'rb') as f:
            try:
                AntchainUtils.put_object(f, {'expected': 'fail'}, url)
                assert False
            except TeaException as e:
                self.assertEqual('NoSuchKey', e.code)
                self.assertEqual(400, e.data['httpCode'])