Skip to content

Commit 37639e6

Browse files
authored
Merge pull request #707 from Thetwam/issue/706-user-agent
Add User-Agent
2 parents d98c4b8 + ea00a36 commit 37639e6

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- Craig Thompson [@craigdsthompson](https://github.com/craigdsthompson)
3636
- Dalton Durst [@UniversalSuperBox](https://github.com/UniversalSuperBox)
3737
- Damian Sweeney [@damianfs](https://github.com/damianfs)
38+
- Daniel Bosk [@dbosk](https://github.com/dbosk)
3839
- Daniel Brinkman [@DanBrink91](https://github.com/DanBrink91)
3940
- Daniel Grobani [@dgrobani](https://github.com/dgrobani)
4041
- Daniel Molares [@dmols](https://github.com/dmols)

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### General
66

77
- Updated `RateLimitExceeded` exception to trigger on HTTP 429 instead of old 403.
8+
- Add a default User-Agent header
89

910
## [3.4.0] - 2025-11-10
1011

canvasapi/requester.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def request(
133133
_url=None,
134134
_kwargs=None,
135135
json=False,
136-
**kwargs
136+
**kwargs,
137137
):
138138
"""
139139
Make a request to the Canvas API and return the response.
@@ -167,6 +167,8 @@ def request(
167167
:type json: `bool`
168168
:rtype: :class:`requests.Response`
169169
"""
170+
from canvasapi import __version__
171+
170172
# Check for specific URL endpoints available from Canvas. If not
171173
# specified, pass the given URL and move on.
172174
if not _url:
@@ -185,6 +187,9 @@ def request(
185187
auth_header = {"Authorization": "Bearer {}".format(self.access_token)}
186188
headers.update(auth_header)
187189

190+
if "User-Agent" not in headers:
191+
headers["User-Agent"] = f"python-canvasapi/{__version__}"
192+
188193
# Convert kwargs into list of 2-tuples and combine with _kwargs.
189194
_kwargs = _kwargs or []
190195
_kwargs.extend(kwargs.items())

0 commit comments

Comments
 (0)