2

my first SO question so I hope that I don't anger the group ;-)

Using gspread 0.4.0 and Python 2.7, I can access pages in my Google Sheet, can read data, and can change the content of cells using update_cell(). However, attempts to insert a row or append a row to the end of the sheet are both met with the following error:

File "c:\Python27\lib\site-packages\gspread\models.py", line 525, in append_row
self.add_rows(1)
File "c:\Python27\lib\site-packages\gspread\models.py", line 507, in add_rows
self.resize(rows=self.row_count + rows)
File "c:\Python27\lib\site-packages\gspread\models.py", line 500, in resize
self._element = self.client.put_feed(uri, ElementTree.tostring(feed))
File "c:\Python27\lib\site-packages\gspread\client.py", line 212, in put_feed
r = self.session.put(url, data, headers=headers)
File "c:\Python27\lib\site-packages\gspread\httpsession.py", line 85, in put
return self.request('PUT', url, data=data, **kwargs)
File "c:\Python27\lib\site-packages\gspread\httpsession.py", line 72, in request
response.status_code, response.content))
spread.exceptions.HTTPError: 400: The reference to entity "format" must end with the ';' delimiter.

I found one hit on the gspread Github page that referenced this error and that user had apparently seen the issue go away when he removed permissions from his sheet. I have removed permissions from mine but the error persists.

I am not the most savvy user of HTTP to update data, and I think that's what gspread is doing here, so I am stumped. There's a lot of """ stuff here that makes my eyes bleed.

Thanks to the collective for any advice/assistance!

steve
  • 31
  • 4
  • 1
    Could you please post a sample of your code with `update_cell()` call? – Burnash Oct 21 '16 at 08:07
  • Hi Burnash, that ship has sailed a long time ago; I don't know why I didn't get notification of your request until tonight, otherwise I would have answered immediately! However, I did eventually track it down to a problem in models.py, where there was an untrapped ampersand being passed on line 501. I modified the local file to read like this, and it works. Hacky but working: `self._element = self.client.put_feed(uri, ElementTree.tostring(feed).replace("&format","&format"))` – steve Dec 04 '16 at 05:06
  • Nice. I wonder what this unescaped ampersand is doing there in the first place since the contents of `feed` are straight from Google's API. Anyway, it's good that you found a solution. Do you know that you can answer your own questions on StackOverflow? – Burnash Dec 07 '16 at 22:27
  • I did not, this was my first time logging in and posting. Now I see the "Answer Your Question" button down below. – steve Dec 10 '16 at 03:22
  • I think you can also accept your own answer to show that it has resolved your issue. – Burnash Dec 10 '16 at 10:08

1 Answers1

1

OK, so in my case it turned out that an unescaped ampersand was being passed to gspread's models.resize() function. I do not know how to solve the unescaped ampersand at its source, so I just replaced it with the proper escaped characters and I'm off to the races.

Specifically, I modified models.py at line 500 (in the resize() function) -

self._element = self.client.put_feed(uri, ElementTree.tostring(feed).replace("&format","&format"))

steve
  • 31
  • 4