1
votes

In Google Drive I want copy a single sheet from a spreadsheet to another spreadsheet so I use this API:

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.sheets/copyTo

I start from 2 spreadsheet that I'm able to open and update using gspread. But when I run the Python code I get a 500 Internal Server Error.

googleapiclient.errors.HttpError: <HttpError 500 when requesting https://sheets.googleapis.com/v4/spreadsheets/myID/sheets/0:copyTo?alt=json returned "Internal error encountered.">

Same results if I test API directly from the API page. Why?

I also check if gspread has a similar api but I don't found nothing of similar

1
I have solved the question using the correct sheet_id. Unfortunately there isnt' an api that return the sheet id but you can get it directly form file file Url. Sheet id is the number following gid= - franco_b
thanks man, you've just saved my I don't know how many hours of beating my head against the wall - lithuak
@izhak accept my answer :) - franco_b

1 Answers

0
votes

I found this library: https://github.com/nithinmurali/pygsheets Is the best way to make operation on drive spreadsheet and worhsheet. The worksheet copy is so simple:

import pygsheets
gc = pygsheets.authorize(outh_file='client_secret.json')
sh = gc.open('shname')
wks = sh.add_worksheet("wksname_b", src_worksheet=sh.worksheet_by_title("wksname_a"))