Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode issue with worksheet.get_values() #1538

Open
deanmalmgren opened this issue Jan 8, 2025 · 1 comment
Open

Unicode issue with worksheet.get_values() #1538

deanmalmgren opened this issue Jan 8, 2025 · 1 comment
Labels

Comments

@deanmalmgren
Copy link

Describe the bug

I have a spreadsheet that has some unicode values in it. When gspread

To Reproduce

  1. Go to this spreadsheet and notice the use of the unicode characters "é" and "–".
  2. Download the values from this Google Sheet using gsheet with the get_values method (see code sample below).
  3. Observe that the characters "È" and "ñ" are used instead.

Expected behavior
Expected the values to include the correct unicode characters "é" and "–"

Code example*

import gspread
gspreadsheet_url = "https://docs.google.com/spreadsheets/d/1ZmBPLAVf-uwapUH8ep4n9mUHbv2kKDb8yw-wqgjsIfk/edit"
gclient, AUTHORIZED_USER = gspread.oauth_from_dict(credentials, AUTHORIZED_USER)
gspreadsheet = gclient.open_by_url(gspreadsheet_url)
gsheet = gspreadsheet.get_worksheet_by_id("0")
values = gsheet.get_values()
print(values)

Screenshots
n/a

Environment info:

  • Operating System: macOS Sequoia 15.2
  • Python version: 3.11.10
  • gspread version: 6.1.4

Stack trace or other output that would be helpful
n/a

Additional context
cc @weichangyuan-phd

@alifeee
Copy link
Collaborator

alifeee commented Jan 22, 2025

hi ! thanks for submitting the issue :]

thanks for providing an example sheet and code example !

using the sheet you provided (copied here)

names
Single Serve Entrée
Micro Dosed – Fountain

and this code:

import gspread

SPREADSHEET_ID = "1ZmBPLAVf-uwapUH8ep4n9mUHbv2kKDb8yw-wqgjsIfk"
gc = gspread.service_account(filename="./creds.json")
gspreadsheet = gc.open_by_key(SPREADSHEET_ID)
gsheet = gspreadsheet.sheet1

values = gsheet.get_values()

for rowi, row in enumerate(values):
    for coli, cell in enumerate(row):
        print(f"column {coli}, row {rowi}")
        print("  string:  ", cell)
        print("  bytes: ", cell.encode("utf-8"))

I get the following result:

$ py 1538-unicode-characters.py 
column 0, row 0
  string:   names
  bytes:  b'names'
column 0, row 1
  string:   Single Serve Entrée
  bytes:  b'Single Serve Entr\xc3\xa9e'
column 0, row 2
  string:   Micro Dosed – Fountain
  bytes:  b'Micro Dosed \xe2\x80\x93 Fountain'

to me, then, it seems like there is no issue. Perhaps the problem is with your terminal or how you use the result?

my environment is:

gspread 6.1.4 with Python 3.10.12 on Linux Pop!_OS 22.04 LTS x86_64

@alifeee alifeee added the Bug label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants