Configure an endpoint

Updated at:
Copy as MD

An endpoint is a domain name of an Alibaba Cloud service, such as ecs.cn-hangzhou.aliyuncs.com.

Configuration methods

The SDK supports two endpoint configuration methods, listed by descending priority:

  1. Method 1: Specify an endpoint (recommended)

    You can specify the endpoint when you initialize the client object of a cloud service. Both public endpoints and VPC endpoints are supported.

    The following sample shows only the endpoint-related configuration:

    from alibabacloud_tea_openapi.models import Config
    
    config = Config(
        # Configure the credential.
        endpoint='<endpoint>'  # endpoint
    )
    
  2. Method 2: Specify a region ID

    If you do not specify an endpoint, you can specify a region ID when you initialize the client object of a cloud service. The SDK then resolves the corresponding endpoint automatically.

    from alibabacloud_tea_openapi.models import Config
    
    config = Config(
        # Configure the credential.
        region_id='cn-hangzhou',  # Specify an endpoint based on the region ID.
    )
    

Authentication endpoint

For some OpenAPI operations that upload files, you can configure a VPC endpoint for the file upload authorization code when you initialize the request client. This makes the network more stable. If you do not configure a VPC endpoint, the default public service address is used, for which global acceleration is already enabled.

  • Configure a VPC endpoint to request file upload authentication information over a VPC.

from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions

from alibabacloud_facebody20191230.models import DetectBodyCountAdvanceRequest
from alibabacloud_facebody20191230.client import Client

runtime = RuntimeOptions()
config = Config(
    # Configure the credential.
    region_id='cn-hangzhou',
    # The endpoint that is used for authentication.
    open_platform_endpoint='openplatform-vpc.cn-shanghai.aliyuncs.com'
)

client = Client(config)
with open('test.txt', 'rb') as f:
    request = DetectBodyCountAdvanceRequest(image_urlobject=f)
    response = client.detect_body_count_advance(request, runtime)
    # The response, which contains the body and headers that are returned by the server side.
    print(response.body)
    print(response.headers)
  • Configure a VPC endpoint to request file upload authentication information over an internal network or VPC.

from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions

from alibabacloud_facebody20191230.models import DetectBodyCountAdvanceRequest
from alibabacloud_facebody20191230.client import Client

runtime = RuntimeOptions()
config = Config(
    # Configure the credential.
    region_id='cn-hangzhou',
    open_platform_endpoint='openplatform-vpc.cn-shanghai.aliyuncs.com',
    endpoint_type='internal' # Configure the Object Storage Service (OSS) endpoint that you want to use to upload the file.
)

client = Client(config)
with open('test.txt', 'rb') as f:
    request = DetectBodyCountAdvanceRequest(image_urlobject=f)
    response = client.detect_body_count_advance(request, runtime)
    # The response, which contains the body and headers that are returned by the server side.
    print(response.body)
    print(response.headers)

Appendix: Find an endpoint

You can find the endpoint of a cloud service in the OpenAPI portal:

  1. From the top menu of the portal, choose Products and select a product, such as ECS.

  2. On the product homepage, find the list of service regions.

  3. Select the endpoint that corresponds to your region ID, and then copy and paste it.

Alternatively, on the API debugging page, click Regions in the left-side navigation pane to view the endpoints supported by the cloud service.