gspread icon indicating copy to clipboard operation
gspread copied to clipboard

update a cell with 50,000 chars - ERROR

Open omersi opened this issue 12 years ago • 7 comments

when trying to update a cell with string longer that 50,000 chars it kills the connection to the spreadsheet. please issue a suitable warning

omersi avatar Dec 01 '14 15:12 omersi

Could you please post a sample traceback from your script?

burnash avatar Dec 22 '14 19:12 burnash

worksheet.update_acell('A100', range(1,10000)) Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/gspread/models.py", line 413, in update_acell return self.update_cell(*(self.get_int_addr(label)), val=val) File "/Library/Python/2.7/site-packages/gspread/models.py", line 429, in update_cell self.client.put_feed(uri, ElementTree.tostring(feed)) File "/Library/Python/2.7/site-packages/gspread/client.py", line 261, in put_feed raise ex HTTPError

omersi avatar Dec 22 '14 21:12 omersi

I've updated gspread so now it returns a message along with this exception. Can you update the library, rerun your code and post the exception message? That'll be very useful for anyone who is trying to work with this amount of text.

burnash avatar Apr 17 '15 16:04 burnash

HI

I updated to 0.2.4

len(a) 50487 spreadsheet.sheet1.update_acell('a1',str(a)) Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/gspread/models.py", line 429, in update_acell return self.update_cell(*(self.get_int_addr(label)), val=val) File "/Library/Python/2.7/site-packages/gspread/models.py", line 445, in update_cell self.client.put_feed(uri, ElementTree.tostring(feed)) File "/Library/Python/2.7/site-packages/gspread/client.py", line 273, in put_feed if ex.code == 403: AttributeError: 'HTTPError' object has no attribute 'code'

It's better since the connection remains open.

is that the intended behavior?

Omer

On Fri, Apr 17, 2015 at 7:05 PM, Anton Burnashev [email protected] wrote:

I've updated gspread so now it returns a message along with this exception. Can you update the library, rerun your code and post the exception message? That'll be very useful for anyone who is trying to work with this amount of text.

— Reply to this email directly or view it on GitHub https://github.com/burnash/gspread/issues/187#issuecomment-94017013.

omersi avatar Apr 19 '15 10:04 omersi

@omersi fixed missing attribute, could you update and try again?

burnash avatar Apr 21 '15 22:04 burnash

I believe this is a duplicate of #148.

msuozzo avatar Oct 11 '15 20:10 msuozzo

@burnash i am trying select a range of columns to fill them with list row wise. I am not sure how to select the range.

import gspread
import os
import datetime
import time

from gspread_dataframe import get_as_dataframe


from oauth2client.service_account import ServiceAccountCredentials
 
#to find next available row 
def next_available_row(sheet):
    str_list = list(filter(None, sheet.col_values(1)))  # fastest
    return str(len(str_list)+1)

# use creds to create a client to interact with the Google Drive API
def update_spreadsheet(data_list):
    
    scope = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']
    basedir = os.path.abspath(os.path.dirname(__file__))
    DATA_JSON = basedir+'/'+'client_secret.json'
    creds = ServiceAccountCredentials.from_json_keyfile_name(DATA_JSON, scope)
    
    client = gspread.authorize(creds)
    
    # Find a workbook by name and open the first sheet
    # Make sure you use the right name here.
    sheet = client.open("mqttsheet").sheet1
   
    next_row = next_available_row(sheet)
#    
#    
#    
#    
    count=int(next_row)
    count-=1
    
    
    #insert on the next available row
    date_today=str(datetime.date.today())
    
    
            
    time_today=time.strftime("%H:%M:%S")
    datalist=[count,date_today,time_today] + data_list
    range_list= sheet.range('A1:L1')
    
    for data,ran in datalist and enumerate(range_list):
        sheet.update_acell(ran.format(next_row),data) 

isrj5 avatar May 17 '18 12:05 isrj5