【发布时间】:2018-11-08 21:44:23
【问题描述】:
Strava API 文档提供了以下示例代码,我复制并输入了我自己的访问令牌和俱乐部 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。
我该如何解决这个问题?
【问题讨论】:
-
好问题。老实说,我不完全确定它是什么,但我猜它包含不在当前 Python 版本中但将在未来版本中的包。我不是 Python 开发人员,我只是第一次看到这个,所以这甚至可能是一个准确的解释。
-
在 Python 3 中不需要
from __future__ ...。请参阅 how to use from __future__ import print_function -
即使我对此发表评论,我也会得到
import swagger_client ModuleNotFoundError: No module named 'swagger_client'
标签: python python-3.x swagger python-import strava