Skip to main content

When I try to get all the activities of the currently authenticated user, I have no problem with the vanilla endpoint with no parameters, ie

https://www.strava.com/api/v3/athlete/activities

returns a list of 30 of the authenticated athlete’s activities.

 

However, if I try to use any of the parameters noted in the documentation, such as

https://www.strava.com/api/v3/athlete/activities?page=1

then I receive the following error:

HTTPError: 403 Client Error: Forbidden for url: https://www.strava.com/api/v3/athlete/activities

 

What am I doing wrong here? I am using the requests library in python, if that is helpful.

Are you getting any kind of error message from the API? I just ran a quick test in postman using the page parameter and I got back valid results.

Maybe share some of the code you’re using to make the requests?

 

 


@ActivityFix Here is all the relevant code and responses. (It won’t let me edit my original post.)

 

Code I’m running:

import requests

# this works, I get valid results
response = requests.get(
url = 'https://www.strava.com/api/v3/athlete/activities',
headers = {'Authorization': 'Bearer ' + access_token},
)
response.raise_for_status()
print(response.text)

# this does not work
response = requests.get(
url = 'https://www.strava.com/api/v3/athlete/activities',
headers = {'Authorization': 'Bearer ' + access_token},
data = {
'page' : '1'
}
)
response.raise_for_status()
print(response.text)

 

Response from the first (working) api call:

e{"resource_state":2,"athlete":{"id":...

 

Response from the second (not working) api call:

---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-67-3bc18d072030> in <cell line: 0>()
15 }
16 )
---> 17 response.raise_for_status()
18 print(response.text)

/usr/local/lib/python3.11/dist-packages/requests/models.py in raise_for_status(self)
1022
1023 if http_error_msg:
-> 1024 raise HTTPError(http_error_msg, response=self)
1025
1026 def close(self):

HTTPError: 403 Client Error: Forbidden for url: https://www.strava.com/api/v3/athlete/activities

 

And if I comment out the line response.raise_for_status() in the second (not working) api call, I get this response:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Bad request.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: 2tJ8jATdcM98QPLdUdNFrGpvyBgg3UBwy1QmoWmW_i41motaOoWkSw==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>

 


@ActivityFix, for some reason I can neither edit my post nor include code in this comment. But I have put my code in this pastebin.


Shouldn't the page argument be passed as params instead of data?

https://requests.readthedocs.io/en/latest/user/quickstart/#passing-parameters-in-urls


Reply