aliyun / aliyun/alibabacloud-python-sdk

ImportError: cannot import name 'Client' from partially initialized module 'alibabacloud_iot20180120.client'

Open
#38 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
139
Forks
38
PR merge metrics
No merged PRs in 30d

Description

这是官方提供的实例代码:
`# -- coding: utf-8 --

This file is auto-generated, don't edit it. Thanks.

import os
import sys

from typing import List

from alibabacloud_iot20180120.client import Client as Iot20180120Client
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_iot20180120 import models as iot_20180120_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient

class Sample:
def init(self):
pass

@staticmethod
def create_client() -> Iot20180120Client:
    """
    使用凭据初始化账号Client
    @return: Client
    @throws Exception
    """
    # 工程代码建议使用更安全的无AK方式,凭据配置方式请参见:https://help.aliyun.com/document_detail/378659.html。
    credential = CredentialClient()
    config = open_api_models.Config(
        credential=credential
    )
    # Endpoint 请参考 https://api.aliyun.com/product/Iot
    config.endpoint = f'iot.cn-shanghai.aliyuncs.com'
    return Iot20180120Client(config)

@staticmethod
def main(
    args: List[str],
) -> None:
    client = Sample.create_client()
    pub_request = iot_20180120_models.PubRequest(
        device_name='',
        iot_instance_id='iot-06z00axxxx',
        product_key='xxxxxxx',
        topic_full_name='/sys/xxxxxxx/xxxx/thing/service/property/set',
        message_content='This is api test'
    )
    runtime = util_models.RuntimeOptions()
    try:
        # 复制代码运行请自行打印 API 的返回值
        client.pub_with_options(pub_request, runtime)
    except Exception as error:
        # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
        # 错误 message
        print(error.message)
        # 诊断地址
        print(error.data.get("Recommend"))
        UtilClient.assert_as_string(error.message)

@staticmethod
async def main_async(
    args: List[str],
) -> None:
    client = Sample.create_client()
    pub_request = iot_20180120_models.PubRequest(
        device_name='',
        iot_instance_id='iot-xxxx',
        product_key='xxxxx',
        topic_full_name='/sys/xxxx/xxxxx/thing/service/property/set',
        message_content='This is api test'
    )
    runtime = util_models.RuntimeOptions()
    try:
        # 复制代码运行请自行打印 API 的返回值
        await client.pub_with_options_async(pub_request, runtime)
    except Exception as error:
        # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
        # 错误 message
        print(error.message)
        # 诊断地址
        print(error.data.get("Recommend"))
        UtilClient.assert_as_string(error.message)

if name == 'main':
Sample.main(sys.argv[1:])
`

Image

但是我自己下载运行时发生报错:

Image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the import failure using the provided generated sample and inspect the alibabacloud_iot20180120.client import path first. Compare the installed package and the generated example dependencies, then verify that the sample can import Client and run without the partially initialized module error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.