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

Update examples of gspread usage /Readme.md #1410

Closed
lightdrk opened this issue Feb 13, 2024 · 8 comments · Fixed by #1431
Closed

Update examples of gspread usage /Readme.md #1410

lightdrk opened this issue Feb 13, 2024 · 8 comments · Fixed by #1431
Labels
Milestone

Comments

@lightdrk
Copy link

Hi,

Their is no usage example of single cell update in the Read me as the example currently is not complete .
simple add worksheet.update_acell('A1', 'Bingo!') to the updating cell example

@alifeee
Copy link
Collaborator

alifeee commented Feb 14, 2024

Hi. Thanks for the issue :)

Do you refer to this section of the readme?

gspread/README.md

Lines 263 to 267 in 4a48fbd

# Update a single cell
worksheet.update('B1', 'Bingo!')
# Update a range
worksheet.update('A1:B2', [[1, 2], [3, 4]])

I notice that this section is wrong. I think it should be

# Update a single cell
-worksheet.update('B1', 'Bingo!')
+worksheet.update_acell('B1', 'Bingo!')

# Update a range
-worksheet.update('A1:B2', [[1, 2], [3, 4]])
+worksheet.update([[1, 2], [3, 4]], 'A1:B2')

I think that all functions in the readme should be tested to make sure they work, as that is the most important part of documentation to get right. This could be as a part of #1413

@alifeee alifeee added the Docs label Feb 14, 2024
@alifeee alifeee added this to the 6.1.0 milestone Feb 14, 2024
@lightdrk
Copy link
Author

Yes , dont know about range but yes for the single one

@alifeee
Copy link
Collaborator

alifeee commented Feb 21, 2024

reopening as I don't think this is changed yet

@alifeee alifeee reopened this Feb 21, 2024
@jeeeepp
Copy link

jeeeepp commented Mar 2, 2024

I have some problems with updating single cell.

from selenium import webdriver
from google.oauth2.service_account import Credentials
import gspread
from humanfriendly import parse_size
from selenium import webdriver
from selenium.webdriver.common.by import By
scopes = [
    'https://www.googleapis.com/auth/spreadsheets',
    'https://www.googleapis.com/auth/drive'
]

credentials = {
 ******
}
likes=[]
comments=[]
saves=[]
shares=[]

gc = gspread.service_account_from_dict(credentials)
sht2 = gc.open_by_url('https://docs.google.com/spreadsheets/d/1zZFqgrN6A4JNIlftQgpbyMHBZadfefFWsU7LpL_BBrwQxu6E/edit?usp=sharing')
worksheet = sht2.get_worksheet(0)
worksheet.update('B1', 'Bingo!')

I got an error. I ever done this in the last week before but the scripts are working.

gspread.exceptions.APIError: {'code': 400, 'message': 'Invalid value at \'data.values\' (type.googleapis.com/google.protobuf.ListValue), "A2"', 'status': 'INVALID_ARGUMENT', 'details': [{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'data.values', 'description': 'Invalid value at \'data.values\' (type.googleapis.com/google.protobuf.ListValue), "A2"'}]}]}
PS C:\Users\Lenovo\Desktop\code\tiktoka-data-mcn>
PS C:\Users\Lenovo\Desktop\code\tiktoka-data-mcn>
PS C:\Users\Lenovo\Desktop\code\tiktoka-data-mcn>
PS C:\Users\Lenovo\Desktop\code\tiktoka-data-mcn> python '.\test,py'
Traceback (most recent call last):
  File "C:\Users\Lenovo\Desktop\code\tiktoka-data-mcn\test,py", line 34, in <module>
    worksheet.update('B1', 'Bingo!')
  File "C:\Users\Lenovo\AppData\Roaming\Python\Python311\site-packages\gspread\worksheet.py", line 1239, in update
    response = self.client.values_update(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Lenovo\AppData\Roaming\Python\Python311\site-packages\gspread\http_client.py", line 168, in values_update
    r = self.request("put", url, params=params, json=body)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Lenovo\AppData\Roaming\Python\Python311\site-packages\gspread\http_client.py", line 123, in request
    raise APIError(response)
gspread.exceptions.APIError: {'code': 400, 'message': 'Invalid value at \'data.values\' (type.googleapis.com/google.protobuf.ListValue), "B1"', 'status': 'INVALID_ARGUMENT', 'details': [{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'data.values', 'description': 'Invalid value at \'data.values\' (type.googleapis.com/google.protobuf.ListValue), "B1"'}]}]}

@alifeee
Copy link
Collaborator

alifeee commented Mar 8, 2024

I have some problems with updating single cell.

Hi. Apologies for the delay.

Please change your code to

- worksheet.update("B1", "Bingo!")
+ worksheet.update_acell("B1", "Bingo!")

and let me know if this works?

We will update the readme to reflect this soon :)

Thanks.

p.s. to @lavigne958: are the arguments of update and update_acell different to one another? I feel the answer is yes.

@lavigne958
Copy link
Collaborator

lavigne958 commented Mar 12, 2024

yes they are ! 😞

the method update is

update(<values>, <range name>, ...)

the method `update_acell is

update_acell(<label>, <single value>)

@alifeee
Copy link
Collaborator

alifeee commented Mar 13, 2024

nice how did this happen

@lavigne958
Copy link
Collaborator

nice how did this happen

I would say it's historic, left over from the past from this repository I suppose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants