diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5cde902..1973cf9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
 
 ## [Unreleased]
 
+### Bugfixes
+
+- Fixed an issue where `util.clean_headers()` would throw a `ValueError` if a user accidentally included a space in their API token. (Thanks, [@keeeeeegan](https://github.com/keeeeeegan))
+
 ## [0.14.0] - 2019-08-20
 
 ### New Endpoint Coverage
diff --git a/canvasapi/canvas.py b/canvasapi/canvas.py
index ec235a7..a574ccc 100644
--- a/canvasapi/canvas.py
+++ b/canvasapi/canvas.py
@@ -58,6 +58,11 @@ class Canvas(object):
                 UserWarning,
             )
 
+        # Ensure that the user-supplied access token contains no leading or
+        # trailing spaces that may cause issues when communicating with
+        # the API.
+        access_token = access_token.strip()
+
         base_url = new_url + "/api/v1/"
 
         self.__requester = Requester(base_url, access_token)
diff --git a/canvasapi/util.py b/canvasapi/util.py
index 976ecdd..5b23b3c 100644
--- a/canvasapi/util.py
+++ b/canvasapi/util.py
@@ -244,12 +244,7 @@ def clean_headers(headers):
 
     authorization_header = headers.get("Authorization")
     if authorization_header:
-        # Grab the actual token (not the "Bearer" prefix)
-        _, token = authorization_header.split(" ")
-
-        # Trim all but the last four characters
-        sanitized = "****" + token[-4:]
-
+        sanitized = "****" + authorization_header[-4:]
         cleaned_headers["Authorization"] = sanitized
 
     return cleaned_headers

Spaces in the API_KEY throw ValueError Exception
# Describe the bug

When the `API_KEY` passed to `Canvas` has a space character in the value, a `ValueError: too many values to unpack (expected 2)` exception is thrown.

# To Reproduce

Steps to reproduce the behavior:

1. Setup `API_URL` and `API_KEY` as normal.
2. Add an additional space character anywhere in the `API_KEY`
3. Setup Canvas object: `canvas = Canvas(API_URL, API_KEY)`
4. Make a call, e.g. `course = canvas.get_course(1)`

# Expected behavior

The whitespace should be automatically removed, or a more useful exception should be thrown.

# Environment information

- Python version (`python --version`)
3.7+
- CanvasAPI version (`pip show canvasapi`)
v0.14.0

# Additional context

```
Traceback (most recent call last):
  File "_test.py", line 42, in <module>
    course = canvas.get_course(COURSE_ID)
  File "<YANKED>canvasapi/canvas.py", line 603, in get_course
    "GET", uri_str.format(course_id), _kwargs=combine_kwargs(**kwargs)
  File "<YANKED>canvasapi/requester.py", line 191, in request
    "Headers: {headers}".format(headers=pformat(clean_headers(headers)))
  File "<YANKED>canvasapi/util.py", line 248, in clean_headers
    _, token = authorization_header.split(" ")
ValueError: too many values to unpack (expected 2)
```
diff --git a/tests/test_canvas.py b/tests/test_canvas.py
index 458759e..5170063 100644
--- a/tests/test_canvas.py
+++ b/tests/test_canvas.py
@@ -70,6 +70,10 @@ class TestCanvas(unittest.TestCase):
                 ),
             )
 
+    def test_init_strips_extra_spaces_in_api_key(self, m):
+        client = Canvas(settings.BASE_URL, " 12345 ")
+        self.assertEqual(client._Canvas__requester.access_token, "12345")
+
     # create_account()
     def test_create_account(self, m):
         register_uris({"account": ["create"]}, m)
diff --git a/tests/test_util.py b/tests/test_util.py
index e10972a..b530100 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -579,3 +579,9 @@ class TestUtil(unittest.TestCase):
 
         cleaned_headers = clean_headers(headers)
         self.assertIsNot(cleaned_headers, headers)
+
+    def test_clean_headers_strips_malformed_keys_correctly(self, m):
+        headers = {"Authorization": "Bearer  123,45"}
+
+        cleaned_headers = clean_headers(headers)
+        self.assertEqual(cleaned_headers["Authorization"], "****3,45")

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest coverage
3.7
requirements.txt dev_requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
Babel==2.14.0
black==23.3.0
-e git+https://github.com/ucfopen/canvasapi.git@fbb4c6106d79673622ff6355eab59d985433fa4b#egg=canvasapi
certifi @ file:///croot/certifi_1671487769961/work/certifi
cfgv==3.3.1
charset-normalizer==3.4.1
click==8.1.8
coverage==7.2.7
distlib==0.3.9
docutils==0.15.2
exceptiongroup==1.2.2
filelock==3.12.2
flake8==5.0.4
identify==2.5.24
idna==3.10
imagesize==1.4.1
importlib-metadata==4.2.0
iniconfig==2.0.0
Jinja2==3.1.6
MarkupSafe==2.1.5
mccabe==0.7.0
mypy-extensions==1.0.0
nodeenv==1.9.1
packaging==24.0
pathspec==0.11.2
platformdirs==2.6.2
pluggy==1.2.0
pre-commit==2.21.0
pycodestyle==2.9.1
pyflakes==2.5.0
Pygments==2.17.2
pytest==7.4.4
pytz==2025.2
PyYAML==6.0.1
requests==2.31.0
requests-mock==1.12.1
six==1.17.0
snowballstemmer==2.2.0
Sphinx==4.3.2
sphinx-rtd-theme==1.3.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
tomli==2.0.1
typed-ast==1.5.5
typing_extensions==4.7.1
urllib3==2.0.7
virtualenv==20.16.2
zipp==3.15.0

name: canvasapi
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - babel==2.14.0
      - black==23.3.0
      - cfgv==3.3.1
      - charset-normalizer==3.4.1
      - click==8.1.8
      - coverage==7.2.7
      - distlib==0.3.9
      - docutils==0.15.2
      - exceptiongroup==1.2.2
      - filelock==3.12.2
      - flake8==5.0.4
      - identify==2.5.24
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==4.2.0
      - iniconfig==2.0.0
      - jinja2==3.1.6
      - markupsafe==2.1.5
      - mccabe==0.7.0
      - mypy-extensions==1.0.0
      - nodeenv==1.9.1
      - packaging==24.0
      - pathspec==0.11.2
      - platformdirs==2.6.2
      - pluggy==1.2.0
      - pre-commit==2.21.0
      - pycodestyle==2.9.1
      - pyflakes==2.5.0
      - pygments==2.17.2
      - pytest==7.4.4
      - pytz==2025.2
      - pyyaml==6.0.1
      - requests==2.31.0
      - requests-mock==1.12.1
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==4.3.2
      - sphinx-rtd-theme==1.3.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - tomli==2.0.1
      - typed-ast==1.5.5
      - typing-extensions==4.7.1
      - urllib3==2.0.7
      - virtualenv==20.16.2
      - zipp==3.15.0
prefix: /opt/conda/envs/canvasapi

tests/test_canvas.py::TestCanvas::test_init_strips_extra_spaces_in_api_key tests/test_util.py::TestUtil::test_clean_headers_strips_malformed_keys_correctly
tests/test_canvas.py::TestCanvas::test_init_deprecate_url_contains_version tests/test_canvas.py::TestCanvas::test_list_appointment_groups tests/test_canvas.py::TestCanvas::test_list_calendar_events tests/test_canvas.py::TestCanvas::test_list_group_participants tests/test_canvas.py::TestCanvas::test_list_user_participants
tests/test_canvas.py::TestCanvas::test_clear_course_nicknames tests/test_canvas.py::TestCanvas::test_conversations_batch_update tests/test_canvas.py::TestCanvas::test_conversations_batch_updated_fail_on_event tests/test_canvas.py::TestCanvas::test_conversations_batch_updated_fail_on_ids tests/test_canvas.py::TestCanvas::test_conversations_get_running_batches tests/test_canvas.py::TestCanvas::test_conversations_mark_all_as_read tests/test_canvas.py::TestCanvas::test_conversations_unread_count tests/test_canvas.py::TestCanvas::test_create_account tests/test_canvas.py::TestCanvas::test_create_appointment_group tests/test_canvas.py::TestCanvas::test_create_appointment_group_fail_on_context_codes tests/test_canvas.py::TestCanvas::test_create_appointment_group_fail_on_title tests/test_canvas.py::TestCanvas::test_create_calendar_event tests/test_canvas.py::TestCanvas::test_create_calendar_event_fail tests/test_canvas.py::TestCanvas::test_create_conversation tests/test_canvas.py::TestCanvas::test_create_conversation_multiple_people tests/test_canvas.py::TestCanvas::test_create_group tests/test_canvas.py::TestCanvas::test_get_account tests/test_canvas.py::TestCanvas::test_get_account_fail tests/test_canvas.py::TestCanvas::test_get_account_sis_id tests/test_canvas.py::TestCanvas::test_get_accounts tests/test_canvas.py::TestCanvas::test_get_activity_stream_summary tests/test_canvas.py::TestCanvas::test_get_announcements tests/test_canvas.py::TestCanvas::test_get_appointment_group tests/test_canvas.py::TestCanvas::test_get_appointment_groups tests/test_canvas.py::TestCanvas::test_get_calendar_event tests/test_canvas.py::TestCanvas::test_get_calendar_events tests/test_canvas.py::TestCanvas::test_get_conversation tests/test_canvas.py::TestCanvas::test_get_conversations tests/test_canvas.py::TestCanvas::test_get_course tests/test_canvas.py::TestCanvas::test_get_course_accounts tests/test_canvas.py::TestCanvas::test_get_course_fail tests/test_canvas.py::TestCanvas::test_get_course_nickname tests/test_canvas.py::TestCanvas::test_get_course_nickname_fail tests/test_canvas.py::TestCanvas::test_get_course_nicknames tests/test_canvas.py::TestCanvas::test_get_course_non_unicode_char tests/test_canvas.py::TestCanvas::test_get_course_sis_id tests/test_canvas.py::TestCanvas::test_get_course_with_start_date tests/test_canvas.py::TestCanvas::test_get_courses tests/test_canvas.py::TestCanvas::test_get_epub_exports tests/test_canvas.py::TestCanvas::test_get_file tests/test_canvas.py::TestCanvas::test_get_group tests/test_canvas.py::TestCanvas::test_get_group_category tests/test_canvas.py::TestCanvas::test_get_group_participants tests/test_canvas.py::TestCanvas::test_get_group_sis_id tests/test_canvas.py::TestCanvas::test_get_outcome tests/test_canvas.py::TestCanvas::test_get_outcome_group tests/test_canvas.py::TestCanvas::test_get_progress tests/test_canvas.py::TestCanvas::test_get_root_outcome_group tests/test_canvas.py::TestCanvas::test_get_section tests/test_canvas.py::TestCanvas::test_get_section_sis_id tests/test_canvas.py::TestCanvas::test_get_todo_items tests/test_canvas.py::TestCanvas::test_get_upcoming_events tests/test_canvas.py::TestCanvas::test_get_user tests/test_canvas.py::TestCanvas::test_get_user_by_id_type tests/test_canvas.py::TestCanvas::test_get_user_fail tests/test_canvas.py::TestCanvas::test_get_user_participants tests/test_canvas.py::TestCanvas::test_get_user_self tests/test_canvas.py::TestCanvas::test_init_warns_when_url_is_blank tests/test_canvas.py::TestCanvas::test_init_warns_when_url_is_http tests/test_canvas.py::TestCanvas::test_init_warns_when_url_is_invalid tests/test_canvas.py::TestCanvas::test_reserve_time_slot tests/test_canvas.py::TestCanvas::test_reserve_time_slot_by_participant_id tests/test_canvas.py::TestCanvas::test_search_accounts tests/test_canvas.py::TestCanvas::test_search_all_courses tests/test_canvas.py::TestCanvas::test_search_recipients tests/test_canvas.py::TestCanvas::test_set_course_nickname tests/test_util.py::TestUtil::test_clean_headers_authorization_stripped tests/test_util.py::TestUtil::test_clean_headers_does_not_mutate_original_dict tests/test_util.py::TestUtil::test_clean_headers_no_authorization tests/test_util.py::TestUtil::test_combine_kwargs_dict_list_dict tests/test_util.py::TestUtil::test_combine_kwargs_empty tests/test_util.py::TestUtil::test_combine_kwargs_multiple_dicts tests/test_util.py::TestUtil::test_combine_kwargs_multiple_mixed tests/test_util.py::TestUtil::test_combine_kwargs_multiple_nested_dicts tests/test_util.py::TestUtil::test_combine_kwargs_nested_dict tests/test_util.py::TestUtil::test_combine_kwargs_single tests/test_util.py::TestUtil::test_combine_kwargs_single_dict tests/test_util.py::TestUtil::test_combine_kwargs_single_generator_empty tests/test_util.py::TestUtil::test_combine_kwargs_single_generator_multiple_items tests/test_util.py::TestUtil::test_combine_kwargs_single_generator_single_item tests/test_util.py::TestUtil::test_combine_kwargs_single_list_empty tests/test_util.py::TestUtil::test_combine_kwargs_single_list_multiple_items tests/test_util.py::TestUtil::test_combine_kwargs_single_list_single_item tests/test_util.py::TestUtil::test_combine_kwargs_super_nested_dict tests/test_util.py::TestUtil::test_combine_kwargs_the_gauntlet tests/test_util.py::TestUtil::test_file_or_path_file tests/test_util.py::TestUtil::test_file_or_path_invalid_path tests/test_util.py::TestUtil::test_file_or_path_valid_path tests/test_util.py::TestUtil::test_get_institution_url tests/test_util.py::TestUtil::test_is_multivalued_bool tests/test_util.py::TestUtil::test_is_multivalued_bytes tests/test_util.py::TestUtil::test_is_multivalued_chain tests/test_util.py::TestUtil::test_is_multivalued_dict tests/test_util.py::TestUtil::test_is_multivalued_dict_items tests/test_util.py::TestUtil::test_is_multivalued_dict_iter tests/test_util.py::TestUtil::test_is_multivalued_dict_keys tests/test_util.py::TestUtil::test_is_multivalued_dict_values tests/test_util.py::TestUtil::test_is_multivalued_generator_call tests/test_util.py::TestUtil::test_is_multivalued_generator_expr tests/test_util.py::TestUtil::test_is_multivalued_integer_types tests/test_util.py::TestUtil::test_is_multivalued_list tests/test_util.py::TestUtil::test_is_multivalued_list_iter tests/test_util.py::TestUtil::test_is_multivalued_set tests/test_util.py::TestUtil::test_is_multivalued_set_iter tests/test_util.py::TestUtil::test_is_multivalued_str tests/test_util.py::TestUtil::test_is_multivalued_tuple tests/test_util.py::TestUtil::test_is_multivalued_tuple_iter tests/test_util.py::TestUtil::test_is_multivalued_unicode tests/test_util.py::TestUtil::test_is_multivalued_zip tests/test_util.py::TestUtil::test_normalize_bool_boolean tests/test_util.py::TestUtil::test_normalize_bool_str_invalid tests/test_util.py::TestUtil::test_normalize_bool_str_lower tests/test_util.py::TestUtil::test_normalize_bool_str_upper tests/test_util.py::TestUtil::test_obj_or_id_int tests/test_util.py::TestUtil::test_obj_or_id_multiple_objs tests/test_util.py::TestUtil::test_obj_or_id_nonuser_self tests/test_util.py::TestUtil::test_obj_or_id_obj tests/test_util.py::TestUtil::test_obj_or_id_obj_no_id tests/test_util.py::TestUtil::test_obj_or_id_str_invalid tests/test_util.py::TestUtil::test_obj_or_id_str_valid tests/test_util.py::TestUtil::test_obj_or_id_user_self tests/test_util.py::TestUtil::test_obj_or_str_invalid_attr_parameter tests/test_util.py::TestUtil::test_obj_or_str_invalid_obj_type tests/test_util.py::TestUtil::test_obj_or_str_mult_obj tests/test_util.py::TestUtil::test_obj_or_str_obj_attr tests/test_util.py::TestUtil::test_obj_or_str_obj_no_attr
canvasapi/util.py canvasapi/canvas.py CHANGELOG.md
canvasapi/util.py canvasapi/canvas.py CHANGELOG.md