如何调用华为云api_华为云sdk / api 调用

华为ECS sdk 调用例子:

from openstack import connection

project_id = 'XXX'

domain = 'XXX'

region = 'XXX'

ak = 'XXX'

sk = 'xxx'

conn = connection.Connection(project_id = project_id,

domain = domain,

region = region,

ak = ak,

sk = sk)

servers = conn.computer.servers()

for server in servers:

print(server.name)

区别:比如企业管理服务,CDN,财务管理,IAM管理等全局服务,r.headers = {"content-type":"application/json","X-language":"en-us","X-Domain-Id":"{{ 需要加上domain_id }}"}, 其中domain_id 即【我的账户】——>[账户ID];

sig = signer.Signer()

# Set the AK/SK to sign and authenticate the request.

sig.Key = ""

sig.Secret = ""

# The following example shows how to set the request URL and parameters to query a VPC list.

r = signer.HttpRequest()

r.scheme = "https"

# Set request Endpoint.

r.host = "rds.cn-east-2.myhuaweicloud.com"

# Specify a request method, such as GET, PUT, POST, DELETE, HEAD, and PATCH.

r.method = "GET"

# Set request URI.

r.uri = "/v1.0/projectId/instances"

# Set parameters for the request URL.

r.query = {"limit": "10"}

# Add header parameters, for example, x-domain-id for invoking a global service and x-project-id for invoking a project-level service.

# r.headers = {"content-type": "application/json"}

# 务必加上 "X-language":"en-us"

r.headers = {"content-type":"application/json","X-language":"en-us"}

# Add a body if you have specified the PUT or POST method. Special characters, such as the double quotation mark ("), contained in the body must be escaped.

r.body = ""

sig.Sign(r)

print(r.headers["X-Sdk-Date"])

print(r.headers["Authorization"])

resp = requests.request(r.method, r.scheme + "://" + r.host + r.uri, headers=r.headers, data=r.body)

print(resp.status_code, resp.reason)

print(resp.content)

另外:账单文档校验:

image.png

你可能感兴趣的:(如何调用华为云api)