SyntaxError: future feature print_statement is not defined

1,908 views
Skip to first unread message

Paul Carron

unread,
May 30, 2018, 5:35:11 AM5/30/18
to Strava API

The Strava API documentation gives the following sample code which I copied and entered my own access token and club ID:

Enter code here...
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)


When I try to run it I get


from future import print_statement SyntaxError: future feature print_statement is not defined
 

I can also see that I will get the same with my swagger_client imports. I've tried installing packages for each but this hasn't made any difference. I read that for the future I should be on > Python 2.7 but I'm currently using 3.6.


How do I resolve this issue?

Hans Lellelid

unread,
May 30, 2018, 10:41:10 PM5/30/18
to Strava API
Just remove that line.  That line is for making python 2.7 code compatible w/ python 3.  (That doesn't apply to you.)

Cheers,
Hans

Terry Jones

unread,
May 30, 2018, 11:10:05 PM5/30/18
to Strava API
It's from __future__ import print_function

Terry


--
You received this message because you are subscribed to the Google Groups "Strava API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to strava-api+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hans Lellelid

unread,
May 31, 2018, 10:31:22 PM5/31/18
to Strava API
Ha, good catch. Yes, print_statement is exactly the opposite! :-)

Paul Carron

unread,
Jun 1, 2018, 4:25:48 AM6/1/18
to Strava API
Thanks guys. That got me a step further but now I get this:

Traceback (most recent call last):
 
File "/Users/me/PycharmProjects/stravakomtracker/clubkomtracker.py", line 3, in <module>
   
import swagger_client
ModuleNotFoundError: No module named 'swagger_client'

I tried getting this, and building the jar, then runnin:
java -jar swagger-codegen-cli-<ver>.jar generate -i https://developers.strava.com/swagger/swagger.json -l python -o ./StravaPythonClient

I ended up with a folder called SwaggerPythonClient which contained a swagger_client folder containing configuration.py and rest.py so I copied the contents to my program directory. The import errors have now vanished but now I'm finding other issues. I can investigate and maybe post in a new question if required but want to check if what I did is correct before I continue. Any thoughts?
Reply all
Reply to author
Forward
0 new messages