gpt4 book ai didi

python - Python 中 __future__ 和 swagger_client 的问题

转载 作者:行者123 更新时间:2023-12-03 20:30:03 24 4
gpt4 key购买 nike

Strava API 文档提供了以下示例代码,我复制并输入了我自己的访问 token 和俱乐部 ID:

from __future__ import print_statement
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint

# Configure OAuth2 access token for authorization: strava_oauth
swagger_client.configuration.access_token = 'MY_ACCESS_TOKEN'

# create an instance of the API class
api_instance = swagger_client.ClubsApi()
id = MY_CLUB_ID # Integer | The identifier of the club.
page = 56 # Integer | Page number. (optional)
perPage = 56 # Integer | Number of items per page. Defaults to 30. (optional) (default to 30)

try:
# List Club Activities
api_response = api_instance.getClubActivitiesById(id, page=page, perPage=perPage)
pprint(api_response)
except ApiException as e:
print("Exception when calling ClubsApi->getClubActivitiesById: %s\n" % e)

我试着运行它我得到
from __future__ import print_statement
SyntaxError: future feature print_statement is not defined

我也可以看到我的 swagger_client 也会得到同样的结果进口。我试过为每个安装软件包,但这没有任何区别。我读了 __future__我应该使用 > Python 2.7,但我目前使用的是 3.6。

我该如何解决这个问题?

最佳答案

1) 第一行包含一个错字

from __future__ import print_statement
^^^

它应该是

from __future__ import print_function

但是由于您使用的是 Python 3,您实际上并不需要此导入 - 有关详细信息,请参阅 this Q&A

2) swagger_client 可能是从 Strava OpenAPI definition 生成的Python客户端。看起来您需要使用 Swagger Codegen 手动生成它。做这件事有很多种方法:
  • 将 Strava OpenAPI 定义粘贴到 https://editor.swagger.io 并选择 Generate Client > Python
  • 安装 command-line versionSwagger Codegen 并运行:
    # Windows
    java -jar swagger-codegen-cli-<ver>.jar generate -i https://developers.strava.com/swagger/swagger.json -l python -o ./StravaPythonClient

    # Mac
    swagger-codegen generate -i https://developers.strava.com/swagger/swagger.json -l python -o ./StravaPythonClient
  • 关于python - Python 中 __future__ 和 swagger_client 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50597854/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com