我通過 Python 發送到電子表格的串列是:
para_enviar_conjunto = [[21], [79]]
此串列是在此代碼上創建的(我沒有添加作業表 ID,因為我試圖保留這段代碼):
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")
我正在嘗試將這些值發送到谷歌電子表格,但是在嘗試發送時,出現此錯誤:
returned "Invalid values[1][0]: list_value {
values {
number_value: 21.0
}
}". Details: "Invalid values[1][0]: list_value {
values {
number_value: 21.0
}
}
">
我應該怎么做才能解決這個問題?
uj5u.com熱心網友回復:
在您的腳本中,values = ((para_enviar_conjunto),)是([[21], [79]],). 我認為這可能是您的問題的原因。那么在這種情況下,下面的修改呢?
從:
value_range_body = {
'majorDimension': 'ROWS',
'values': values
}
到:
value_range_body = {
'majorDimension': 'ROWS',
'values': para_enviar_conjunto
}
- 在這種情況下,您可以洗掉
values = ((para_enviar_conjunto),).
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/416119.html
標籤:
