gspread icon indicating copy to clipboard operation
gspread copied to clipboard

Error updating tab color

Open royrusso opened this issue 7 months ago • 4 comments

Important: Please do not post usage questions here. To get a quick response, please ask a question on Stack Overflow using gspread tag. See existing questions: https://stackoverflow.com/questions/tagged/gspread


Describe the bug Unable to change tab color.

`2025-07-25 09:49:30.077 | ERROR | main:main:91 - An unexpected error occurred: 'dict' object has no attribute 'lstrip' Traceback (most recent call last):

File "/Users/rrusso/.pyenv/versions/3.13.4/lib/python3.13/runpy.py", line 198, in _run_module_as_main return _run_code(code, main_globals, None, │ │ └ {'name': 'main', 'doc': None, 'package': 'engineering_reports', 'loader': <_frozen_importlib_external.Sou... │ └ <code object at 0x1047e17a0, file "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled... └ <function _run_code at 0x1047e8720> File "/Users/rrusso/.pyenv/versions/3.13.4/lib/python3.13/runpy.py", line 88, in _run_code exec(code, run_globals) │ └ {'name': 'main', 'doc': None, 'package': 'engineering_reports', 'loader': <_frozen_importlib_external.Sou... └ <code object at 0x1047e17a0, file "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled...

File "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/main.py", line 71, in cli.main() │ └ <function main at 0x1086c4b80> └ <module 'debugpy.server.cli' from '/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/deb...

File "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 501, in main run() └ <function run_module at 0x1086c49a0>

File "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 384, in run_module run_module_as_main(options.target, alter_argv=True) │ │ └ 'engineering_reports.main' │ └ <debugpy.server.cli.Options object at 0x107fbc2f0> └ <function _run_module_as_main at 0x107dbaca0>

File "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 228, in _run_module_as_main return _run_code(code, main_globals, None, "main", mod_spec) │ │ │ └ ModuleSpec(name='engineering_reports.main', loader=<_frozen_importlib_external.SourceFileLoader object at 0x1087263f0>, origi... │ │ └ {'name': 'main', 'doc': None, 'package': 'engineering_reports', 'loader': <_frozen_importlib_external.Sou... │ └ <code object at 0x108718a50, file "/Users/rrusso/projects/engineering_reports/src/engineering_reports/main.py", line 1> └ <function _run_code at 0x107dba700>

File "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 118, in _run_code exec(code, run_globals) │ └ {'name': 'main', 'doc': None, 'package': 'engineering_reports', 'loader': <_frozen_importlib_external.Sou... └ <code object at 0x108718a50, file "/Users/rrusso/projects/engineering_reports/src/engineering_reports/main.py", line 1>

File "/Users/rrusso/projects/engineering_reports/src/engineering_reports/main.py", line 99, in main() └ <function main at 0x10acc8540>

File "/Users/rrusso/projects/engineering_reports/src/engineering_reports/main.py", line 85, in main GoogleAPIService().generate_google_sheets_report() └ <class 'engineering_reports.service.google_api_service.GoogleAPIService'>

File "/Users/rrusso/projects/engineering_reports/src/engineering_reports/service/google_api_service.py", line 14, in generate_google_sheets_report worksheet.update_tab_color({"red": 0.2, "green": 0.0, "blue": 0.8}) │ └ <function Worksheet.update_tab_color at 0x10acb6020> └ <Worksheet 'Epics' id:1351696836>

File "/Users/rrusso/Library/Caches/pypoetry/virtualenvs/reporting-WvGKL2XU-py3.13/lib/python3.13/site-packages/gspread/worksheet.py", line 1627, in update_tab_color color_dict = convert_hex_to_colors_dict(color) │ └ {'red': 0.2, 'green': 0.0, 'blue': 0.8} └ <function convert_hex_to_colors_dict at 0x10ac59a80> File "/Users/rrusso/Library/Caches/pypoetry/virtualenvs/reporting-WvGKL2XU-py3.13/lib/python3.13/site-packages/gspread/utils.py", line 857, in convert_hex_to_colors_dict hex_color = hex_color.lstrip("#") └ {'red': 0.2, 'green': 0.0, 'blue': 0.8}

AttributeError: 'dict' object has no attribute 'lstrip'`

To Reproduce

Expected behavior

Expected to have tab color change. Expected color dict to be acceptable params.

Code example*

gc: gspread.Client = gspread.oauth() spreadsheet = gc.open("Engineering Reports") worksheet = spreadsheet.worksheet("Epics") worksheet.update_acell("A1", "Hello, World!") worksheet.update_tab_color({"red": 0.2, "green": 0.0, "blue": 0.8})

Screenshots If applicable, add screenshots to help explain your problem.

Environment info:

  • OSX 15.5
  • Python 3.13 requires-python = ">=3.13,<4.0" dependencies = [ "loguru (>=0.7.3,<0.8.0)", "jira @ https://github.com/pycontribs/jira/releases/download/3.10.1/jira-3.10.1-py3-none-any.whl", "environs (>=14.2.0,<15.0.0)", "sqlalchemy (>=2.0.41,<3.0.0)", "gspread (>=6.2.1,<7.0.0)", ]

Stack trace or other output that would be helpful

`2025-07-25 09:49:30.077 | ERROR | main:main:91 - An unexpected error occurred: 'dict' object has no attribute 'lstrip' Traceback (most recent call last):

File "/Users/rrusso/.pyenv/versions/3.13.4/lib/python3.13/runpy.py", line 198, in _run_module_as_main return _run_code(code, main_globals, None, │ │ └ {'name': 'main', 'doc': None, 'package': 'engineering_reports', 'loader': <_frozen_importlib_external.Sou... │ └ <code object at 0x1047e17a0, file "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled... └ <function _run_code at 0x1047e8720> File "/Users/rrusso/.pyenv/versions/3.13.4/lib/python3.13/runpy.py", line 88, in _run_code exec(code, run_globals) │ └ {'name': 'main', 'doc': None, 'package': 'engineering_reports', 'loader': <_frozen_importlib_external.Sou... └ <code object at 0x1047e17a0, file "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled...

File "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/main.py", line 71, in cli.main() │ └ <function main at 0x1086c4b80> └ <module 'debugpy.server.cli' from '/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/deb...

File "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 501, in main run() └ <function run_module at 0x1086c49a0>

File "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 384, in run_module run_module_as_main(options.target, alter_argv=True) │ │ └ 'engineering_reports.main' │ └ <debugpy.server.cli.Options object at 0x107fbc2f0> └ <function _run_module_as_main at 0x107dbaca0>

File "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 228, in _run_module_as_main return _run_code(code, main_globals, None, "main", mod_spec) │ │ │ └ ModuleSpec(name='engineering_reports.main', loader=<_frozen_importlib_external.SourceFileLoader object at 0x1087263f0>, origi... │ │ └ {'name': 'main', 'doc': None, 'package': 'engineering_reports', 'loader': <_frozen_importlib_external.Sou... │ └ <code object at 0x108718a50, file "/Users/rrusso/projects/engineering_reports/src/engineering_reports/main.py", line 1> └ <function _run_code at 0x107dba700>

File "/Users/rrusso/.vscode/extensions/ms-python.debugpy-2025.10.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 118, in _run_code exec(code, run_globals) │ └ {'name': 'main', 'doc': None, 'package': 'engineering_reports', 'loader': <_frozen_importlib_external.Sou... └ <code object at 0x108718a50, file "/Users/rrusso/projects/engineering_reports/src/engineering_reports/main.py", line 1>

File "/Users/rrusso/projects/engineering_reports/src/engineering_reports/main.py", line 99, in main() └ <function main at 0x10acc8540>

File "/Users/rrusso/projects/engineering_reports/src/engineering_reports/main.py", line 85, in main GoogleAPIService().generate_google_sheets_report() └ <class 'engineering_reports.service.google_api_service.GoogleAPIService'>

File "/Users/rrusso/projects/engineering_reports/src/engineering_reports/service/google_api_service.py", line 14, in generate_google_sheets_report worksheet.update_tab_color({"red": 0.2, "green": 0.0, "blue": 0.8}) │ └ <function Worksheet.update_tab_color at 0x10acb6020> └ <Worksheet 'Epics' id:1351696836>

File "/Users/rrusso/Library/Caches/pypoetry/virtualenvs/reporting-WvGKL2XU-py3.13/lib/python3.13/site-packages/gspread/worksheet.py", line 1627, in update_tab_color color_dict = convert_hex_to_colors_dict(color) │ └ {'red': 0.2, 'green': 0.0, 'blue': 0.8} └ <function convert_hex_to_colors_dict at 0x10ac59a80> File "/Users/rrusso/Library/Caches/pypoetry/virtualenvs/reporting-WvGKL2XU-py3.13/lib/python3.13/site-packages/gspread/utils.py", line 857, in convert_hex_to_colors_dict hex_color = hex_color.lstrip("#") └ {'red': 0.2, 'green': 0.0, 'blue': 0.8}

AttributeError: 'dict' object has no attribute 'lstrip'`

Additional context Add any other context about the problem here.

royrusso avatar Jul 25 '25 13:07 royrusso

Note that I was able to get it working by passing the color in Hex

gc: gspread.Client = gspread.oauth() spreadsheet = gc.open("Engineering Reports") worksheet = spreadsheet.worksheet("Epics") worksheet.update_tab_color("#FF0000") # Example: Set tab color to red

The current docs, seem to suggest using a dict with RGB floats.

https://docs.gspread.org/en/latest/user-guide.html#updating-a-worksheet-s-name-and-color

royrusso avatar Jul 25 '25 14:07 royrusso

hi! thanks for making this issue

do you think the documentation is broken, or the code? or both?

alifeee avatar Jul 27 '25 14:07 alifeee

I think an easy fix would be to just edit the docs to prefer Hex values and call it a day.

royrusso avatar Jul 27 '25 20:07 royrusso

I think an easy fix would be to just edit the docs to prefer Hex values and call it a day.

would you like to do that? ;]

alifeee avatar Jul 28 '25 10:07 alifeee