My list to send to spreadsheet via Python is:
para_enviar_conjunto = [[21], [79]]
This list is created on this code (I didn't add the sheet id because I tried to preserve this piece of code):
import requests
from Google import Create_Service
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}
CLIENT_SECRET_FILE = 'client_secrets.json'
API_NAME = 'sheets'
API_VERSION = 'v4'
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
spreadsheet_id = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
spreadsheets_match_id = ['9647082','9979984']
spreadsheets_match_minute = [27,85]
para_enviar_conjunto = []
for (id,minute) in zip(spreadsheets_match_id, spreadsheets_match_minute):
url = f'XXXXXXXXXXXXXXXXXXXXXX/{id}/XXXXXXXXXXXXXXXXXXXXXX'
response = requests.get(url, headers=headers).json()
incidents = response['incidents']
list_of_goals = []
if any(i['incidentType'] == 'goal' for i in response['incidents']):
for incident in incidents:
if (incident['incidentType'] == 'goal' and incident['time'] <= minute):
list_of_goals.append(incident['time'])
else:
list_of_goals.append([0])
if (len(list_of_goals) == 0):
list_of_goals.append([0])
else:
pass
para_enviar_conjunto.append([list_of_goals[0]])
print(para_enviar_conjunto)
worksheet_name = 'MaxLevel'
cell_range_insert = 'AC2:AC'
values = (
(para_enviar_conjunto),
)
value_range_body = {
'majorDimension': 'ROWS',
'values': values
}
service.spreadsheets().values().append(
spreadsheetId=spreadsheet_id,
valueInputOption='USER_ENTERED',
range=worksheet_name '!' cell_range_insert,
body=value_range_body
).execute()
print("Fim")
I'm trying to send these values to a google spreadsheet, but when trying to send, this error appears:
returned "Invalid values[1][0]: list_value {
values {
number_value: 21.0
}
}". Details: "Invalid values[1][0]: list_value {
values {
number_value: 21.0
}
}
">
What should I do to resolve this issue?
CodePudding user response:
In your script, values = ((para_enviar_conjunto),) is ([[21], [79]],). I thought that this might be the reason of your issue. So in this case, how about the following modification?
From:
value_range_body = {
'majorDimension': 'ROWS',
'values': values
}
To:
value_range_body = {
'majorDimension': 'ROWS',
'values': para_enviar_conjunto
}
- In this case, you can remove
values = ((para_enviar_conjunto),).
