Exemple #1
0
    def call(self, action, params, options=None):
        if options is None:
            options = {}
        endpoint = self._get_endpoint()
        headers = {}
        if options.get("IsMultipart"):
            headers["Content-Type"] = _multipart_content

        req_inter = RequestInternal(endpoint,
                                    self.profile.httpProfile.reqMethod,
                                    self._requestPath,
                                    header=headers)
        self._build_req_inter(action, params, req_inter)

        apiRequest = ApiRequest(self._get_endpoint(),
                                self.profile.httpProfile.reqTimeout)

        resp_inter = apiRequest.send_request(req_inter)
        self._check_status(resp_inter)
        data = resp_inter.data
        if sys.version_info[0] > 2:
            data = data.decode()
        else:
            data = data.decode(encoding='UTF-8')
        return data
    def call_octet_stream(self, action, headers, body):
        """
        Invoke API with application/ocet-stream content-type.

        Note:
        1. only specific API can be invoked in such manner.
        2. only TC3-HMAC-SHA256 signature method can be specified.
        3. only POST request method can be specified

        :type action: str
        :param action: Specific API action name.
        :type headers: dict
        :param headers: Header parameters for this API.
        :type body: bytes
        :param body: Bytes of requested body
        """
        if self.profile.signMethod != "TC3-HMAC-SHA256":
            raise SDKError("ClientError", "Invalid signature method.")
        if self.profile.httpProfile.reqMethod != "POST":
            raise SDKError("ClientError", "Invalid request method.")

        req = RequestInternal(self._get_endpoint(),
                              self.profile.httpProfile.reqMethod,
                              self._requestPath)
        for key in headers:
            req.header[key] = headers[key]
        req.data = body
        options = {"IsOctetStream": True}
        self._build_req_inter(action, None, req, options)

        resp = self.request.send_request(req)
        self._check_status(resp)
        data = resp.data
        if sys.version_info[0] > 2:
            data = data.decode()
        else:
            data = data.decode('UTF-8')

        json_rsp = json.loads(data)
        if "Error" in json_rsp["Response"]:
            code = json_rsp["Response"]["Error"]["Code"]
            message = json_rsp["Response"]["Error"]["Message"]
            reqid = json_rsp["Response"]["RequestId"]
            raise TencentCloudSDKException(code, message, reqid)
        return json_rsp
    def call(self, action, params, options=None, headers=None):
        req = RequestInternal(self._get_endpoint(),
                              self.profile.httpProfile.reqMethod,
                              self._requestPath,
                              header=headers)
        self._build_req_inter(action, params, req, options)

        resp_inter = self.request.send_request(req)
        self._check_status(resp_inter)
        data = resp_inter.data
        return data
    def call(self, action, params, options=None):
        req = RequestInternal(self._get_endpoint(),
                              self.profile.httpProfile.reqMethod,
                              self._requestPath)
        self._build_req_inter(action, params, req, options)

        resp_inter = self.request.send_request(req)
        self._check_status(resp_inter)
        data = resp_inter.data
        if sys.version_info[0] > 2:
            data = data.decode()
        else:
            data = data.decode('UTF-8')
        return data
    def call(self, action, params):
        endpoint = self._get_endpoint()

        req_inter = RequestInternal(endpoint,
                                    self.profile.httpProfile.reqMethod,
                                    self._requestPath)
        self._build_req_inter(action, params, req_inter)

        apiRequest = ApiRequest(self._get_endpoint(),
                                self.profile.httpProfile.reqTimeout)

        resp_inter = apiRequest.send_request(req_inter)
        self._check_status(resp_inter)
        data = resp_inter.data
        if sys.version_info[0] > 2:
            data = data.decode()
        else:
            data = data.decode(encoding='UTF-8')
        return data