Skip to main content

I'm trying to write code that iterates over segment efforts. I'm trying to do something like this:

efforts = client.get_segment_efforts(segment_id, athlete_id, since, to)
for effort in efforts:
print(effort)

# I've also tried:
print("Number retrieved:", len(list(efforts)))

Both of these give me the error:

FAILED (errors=1)
No rates present in response headers

File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/stravalib/client.py", line 2038, in _fill_buffer
new_entity = self.entity.parse_obj(
^^^^^^^^^^^^^^^^^^^^^^
File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
File "pydantic/main.py", line 1074, in pydantic.main.validate_model
File "pydantic/fields.py", line 857, in pydantic.fields.ModelField.validate
pydantic.errors.ConfigError: field "activity" not yet prepared so type is still a ForwardRef, you might need to call BaseEffort.update_forward_refs().

 I've searched the web and found zero examples of using the BatchedResultsIterator object returned. Zero. The code that works, doesn't use the Strava Python API and just uses the requests library. The one semi example that I found was here: https://pythonhosted.org/stravalib/usage/overview.html 

And had this code, which generates the same error for me:

activities = client.get_activities(limit=10)
assert len(list(activities)) == 10

Also concerning is the error "No rates present in response headers". What does that mean?

Bill

I'm responding to my own question with more information. I don't think I'm having permission problems because I can call get_activities() and get_segment() without issues. For the get_activities, the call to get them and convert it to a list takes some time (a second or two), but the code finishes and everything is retrieved. But when I try to get_segment_efforts() it returns immediately with no error, but if I try to convert the BatchedResultsIterator into a list, even after waiting tens of seconds, I still get the error:

File "pydantic/fields.py", line 857, in pydantic.fields.ModelField.validate
pydantic.errors.ConfigError: field "activity" not yet prepared so type is still a ForwardRef, you might need to call BaseEffort.update_forward_refs().

Has anyone successfully called the get_segment_efforts() method?


Responding again to this issue. I can get the efforts using this HTTP request:

https://www.strava.com/api/v3/segment_efforts?segment_id=30545810&per_page=200&page=1

This works great and returns me 200 efforts. The problem is that if I bump the page value to 2, or any other number, I just get back the same 200 efforts. I know there are 550 of these efforts from my get_segment() request. Is this a bug or am I doing something wrong?


If you look at the documentation on getEffortsBySegmentId there is no page parameter. I believe it was deprecated about 2 years ago. Instead if you want to retrieve all of the efforts, you need to use the start_date_local and end_date_local parameters.

As far as the forward reference error, I think that is a bug in the Python library. I did a quick test and was able to reproduce the error you are seeing. I then hacked up client.py and changed the field override for activity in the definition of BaseEffort to use the type MetaActivity instead of Activity. After doing that I was able to iterate over results, though the results seemed to be in random order instead of in order of increasing date. I don't have time to dig into unfamiliar code and debug further so I'll leave that for you or one of the developers of the library.


Reply