2525Region = ""
2626Host = ""
2727ContentType = ""
28+ Scheme = "https"
2829
2930
3031def norm_query (params ):
@@ -59,7 +60,17 @@ def hash_sha256(content: str):
5960
6061
6162# 第二步:签名请求函数
62- def request (method , date , query , header , ak , sk , action , body ):
63+ def request (
64+ method ,
65+ date ,
66+ query ,
67+ header ,
68+ ak ,
69+ sk ,
70+ action ,
71+ body ,
72+ scheme : Literal ["http" , "https" ] = "https" ,
73+ ):
6374 # 第三步:创建身份证明。其中的 Service 和 Region 字段是固定的。ak 和 sk 分别代表
6475 # AccessKeyID 和 SecretAccessKey。同时需要初始化签名结构体。一些签名计算时需要的属性也在这里处理。
6576 # 初始化身份证明结构体
@@ -151,7 +162,7 @@ def request(method, date, query, header, ak, sk, action, body):
151162 # 第六步:将 Signature 签名写入 HTTP Header 中,并发送 HTTP 请求。
152163 r = requests .request (
153164 method = method ,
154- url = "https ://{}{}" . format ( request_param [" host" ], request_param [" path" ]) ,
165+ url = f" { scheme } ://{ request_param [' host' ] } { request_param [' path' ] } " ,
155166 headers = header ,
156167 params = request_param ["query" ],
157168 data = request_param ["body" ],
@@ -175,6 +186,7 @@ def ve_request(
175186 header : dict = {},
176187 query : dict = {},
177188 method : Literal ["GET" , "POST" , "PUT" , "DELETE" ] = "POST" ,
189+ scheme : Literal ["http" , "https" ] = "https" ,
178190):
179191 global Service
180192 Service = service
@@ -186,6 +198,8 @@ def ve_request(
186198 Host = host
187199 global ContentType
188200 ContentType = content_type
201+ global Scheme
202+ Scheme = scheme
189203 AK = ak
190204 SK = sk
191205 now = datetime .datetime .utcnow ()
@@ -195,7 +209,15 @@ def ve_request(
195209
196210 try :
197211 response_body = request (
198- method , now , query , header , AK , SK , action , json .dumps (request_body )
212+ method ,
213+ now ,
214+ query ,
215+ header ,
216+ AK ,
217+ SK ,
218+ action ,
219+ json .dumps (request_body ),
220+ Scheme ,
199221 )
200222 return response_body
201223 except Exception as e :
0 commit comments