diff --git a/AUTHORS.md b/AUTHORS.md index fb1924bd..7df4e013 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -35,6 +35,7 @@ - Craig Thompson [@craigdsthompson](https://github.com/craigdsthompson) - Dalton Durst [@UniversalSuperBox](https://github.com/UniversalSuperBox) - Damian Sweeney [@damianfs](https://github.com/damianfs) +- Daniel Bosk [@dbosk](https://github.com/dbosk) - Daniel Brinkman [@DanBrink91](https://github.com/DanBrink91) - Daniel Grobani [@dgrobani](https://github.com/dgrobani) - Daniel Molares [@dmols](https://github.com/dmols) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b588a7d..f10175b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### General - Updated `RateLimitExceeded` exception to trigger on HTTP 429 instead of old 403. +- Add a default User-Agent header ## [3.4.0] - 2025-11-10 diff --git a/canvasapi/requester.py b/canvasapi/requester.py index 5af21bcb..abb0e2af 100644 --- a/canvasapi/requester.py +++ b/canvasapi/requester.py @@ -133,7 +133,7 @@ def request( _url=None, _kwargs=None, json=False, - **kwargs + **kwargs, ): """ Make a request to the Canvas API and return the response. @@ -167,6 +167,8 @@ def request( :type json: `bool` :rtype: :class:`requests.Response` """ + from canvasapi import __version__ + # Check for specific URL endpoints available from Canvas. If not # specified, pass the given URL and move on. if not _url: @@ -185,6 +187,9 @@ def request( auth_header = {"Authorization": "Bearer {}".format(self.access_token)} headers.update(auth_header) + if "User-Agent" not in headers: + headers["User-Agent"] = f"python-canvasapi/{__version__}" + # Convert kwargs into list of 2-tuples and combine with _kwargs. _kwargs = _kwargs or [] _kwargs.extend(kwargs.items())