TencentCloud / tencentcloud-sdk-python

Tencent Cloud API 3.0 SDK for Python
Apache License 2.0
613 stars 251 forks source link

[TencentCloudSDKException] code:InvalidParameterValue message:The value `50` specified in the parameter `SystemDisk.DiskSize` is not valid #12

Closed Shengpei-Luke-Chen closed 6 years ago

Shengpei-Luke-Chen commented 6 years ago

我在query instance的价格,是个很简单的函数。用的基本都是默认值。

def query_instance_price(self):
        def instance_obj_2_param(obj):
            param = {
                "Placement": {
                    "Zone": "ap-guangzhou-3"
                },
                "ImageId": "img-lsttqmsl",
                "InstanceChargeType": "POSTPAID_BY_HOUR",
                "InstanceType": "S3.LARGE16",
                "SystemDisk": {
                    "DiskType": "LOCAL_BASIC", 
                },
                "InternetAccessible": {
                    "InternetChargeType": "BANDWIDTH_POSTPAID_BY_HOUR",
                    "InternetMaxBandwidthOut": 10,
                    "PublicIpAssigned": True
                },
                "InstanceCount": 1,
                "LoginSettings": {
                    "Password": obj.root_pwd
                }
            }
            return param

        module = 'cvm'
        action = 'InquiryPriceRunInstances'
        client = cvm_client.CvmClient(self.cred, self.config['region'])
        client._endpoint = self.endpoint.format(module)
        req = models.InquiryPriceRunInstancesRequest()

        params = instance_obj_2_param(instance_obj)
        req.from_json_string(json.dumps(params))

        resp = client.InquiryPriceRunInstances(req)
        return resp

得到的错误信息如下。

Thanks ahead.

Shengpei-Luke-Chen commented 6 years ago

我自己找到原因了,就是“此instance type不支持此类DiskType” 而各个instance type所支持的disk type,可以在 DescribeZoneInstanceConfigInfos 等里面找到。用户可以自行先检查是否支持,然后再query或者run

我的建议:

祝各位诸事顺利 :laughing:

zqfan commented 6 years ago

这是CVM业务返回的错误消息,的确对开发者很不友好。

zqfan commented 6 years ago

鉴于这个是cvm api的返回,sdk这边目前并不会去做特殊处理,只能靠底层去优化体验问题了。 专门的exception目前来看不会去做,因为错误码实在是太多了,如有对此特殊错误的处理需要,可以捕获通用异常,通过异常的code字段进行错误码判断哈。