Skip to content

ImportError: cannot import name 'Config' from 'openapi' #172

@fspwf

Description

@fspwf

问题描述

成功“pip install longport”并设置三个”Setting environment variables“后,按官网指引运行以下代码验证是否可获取股票基本信息,出现以下报错:
ImportError: cannot import name 'Config' from 'openapi'

错误是"from longport.openapi import Config, QuoteContext"这一语句导致,而我发现openapi.py内容为空,所以出现这个报错?请问这个问题是我安装longport的方法有问题,还是有什么其他原因?

代码例子

from longport.openapi import Config, QuoteContext

# Load configuration from environment variables
config = Config.from_env()

# Create a context for quote APIs
ctx = QuoteContext(config)

# Get basic information of securities
resp = ctx.quote(["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"])
print(resp)

错误信息或结果截图

如果可以,请给出一些执行的结果截图,最好给完整截图,避免关键信息遗漏(请注意保护你的 Access Token)

你的环境信息

  • 操作系统: Windows 11
  • 开发语言: Python
  • SDK 版本号:v2.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions