我试图使用gspread API,我以前用它与数组没有问题,但现在当我尝试使用Numpy数组,我得到“无效值在'data[0].values[0]”API异常。在我的代码片段中,maturities_1是一个由浮点数组成的numpy数组
sh = gc.open_by_key('API_KEY_HERE')
tempWorksheet = sh.worksheet(SomeSheetName)
strengths_1 = np.round(maturities_1, 3).astype(float).tolist()
tempWorksheet.batch_update([{
'range': 'D3:D'+str(len(strengths_1)+2),
'values': strengths_1,
}])
然后抛出这个异常
Traceback (most recent call last):
File "/home/pekabex/termopara/server.py", line 1131, in <module>
calculateStrength(args)
File "/home/pekabex/termopara/server.py", line 808, in calculateStrength
tempWorksheet.batch_update([{
File "/usr/local/lib/python3.9/dist-packages/gspread/utils.py", line 705, in wrapper
return f(*args, **kwargs)
File "/usr/local/lib/python3.9/dist-packages/gspread/worksheet.py", line 1205, in batch_update
response = self.spreadsheet.values_batch_update(body=body)
File "/usr/local/lib/python3.9/dist-packages/gspread/spreadsheet.py", line 220, in values_batch_update
r = self.client.request("post", url, params=params, json=body)
File "/usr/local/lib/python3.9/dist-packages/gspread/client.py", line 93, in request
raise APIError(response)
gspread.exceptions.APIError: {'code': 400, 'message': "Invalid value at 'data[0].values[0]' (type.googleapis.com/google.protobuf.ListValue), 0.769\nInvalid value at 'data[0].values[1]' (type.googleapis.com/google.protobuf.ListValue), 1.748\nInvalid value at 'data[0].values[2]' (type.googleapis.com/google.protobuf.ListValue), 1.758\nInvalid value at 'data[0].values[3]' (type.googleapis.com/google.protobuf.ListValue), 1.806\nInvalid value at 'data[0].values[4]' (type.googleapis.com/google.protobuf.ListValue), 1.806\nInvalid value at 'data[0].values[5]' (type.googleapis.com/google.protobuf.ListValue), 1.873\nInvalid value at 'data[0].values[6]' (type.googleapis.com/google.protobuf.ListValue), 1.921\nInvalid value at 'data[0].values[7]' (type.googleapis.com/google.protobuf.ListValue), 1.969\nInvalid value at 'data[0].values[8]' (type.googleapis.com/google.protobuf.ListValue), 2.007\nInvalid value at 'data[0].values[9]' (type.googleapis.com/google.protobuf.ListValue), 2.055\nInvalid value at 'data[0].values[10]' (type.googleapis.com/google.protobuf.ListValue), 2.103\nInvalid value at 'data[0].values[11]' (type.googleapis.com/google.protobuf.ListValue), 2.15\nInvalid value at 'data[0].values[12]' (type.googleapis.com/google.protobuf.ListValue), 2.198\nInvalid value at 'data[0].values[13]' (type.googleapis.com/google.protobuf.ListValue), 2.302\nInvalid value at 'data[0].values[14]' (type.googleapis.com/google.protobuf.ListValue), 2.349\nInvalid value at 'data[0].values[15]' (type.googleapis.com/google.protobuf.ListValue), 2.359\nInvalid value at 'data[0].values[16]' (type.googleapis.com/google.protobuf.ListValue), 2.406\nInvalid value at 'data[0].values[17]' (type.googleapis.com/google.protobuf.ListValue), 2.406", 'status': 'INVALID_ARGUMENT', 'details': [{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'data[0].values[0]', 'description': "Invalid value at 'data[0].values[0]' (type.googleapis.com/google.protobuf.ListValue), 0.769"}, {'field': 'data[0].values[1]', 'description': "Invalid value at 'data[0].values[1]' (type.googleapis.com/google.protobuf.ListValue), 1.748"}, {'field': 'data[0].values[2]', 'description': "Invalid value at 'data[0].values[2]' (type.googleapis.com/google.protobuf.ListValue), 1.758"}, {'field': 'data[0].values[3]', 'description': "Invalid value at 'data[0].values[3]' (type.googleapis.com/google.protobuf.ListValue), 1.806"}, {'field': 'data[0].values[4]', 'description': "Invalid value at 'data[0].values[4]' (type.googleapis.com/google.protobuf.ListValue), 1.806"}, {'field': 'data[0].values[5]', 'description': "Invalid value at 'data[0].values[5]' (type.googleapis.com/google.protobuf.ListValue), 1.873"}, {'field': 'data[0].values[6]', 'description': "Invalid value at 'data[0].values[6]' (type.googleapis.com/google.protobuf.ListValue), 1.921"}, {'field': 'data[0].values[7]', 'description': "Invalid value at 'data[0].values[7]' (type.googleapis.com/google.protobuf.ListValue), 1.969"}, {'field': 'data[0].values[8]', 'description': "Invalid value at 'data[0].values[8]' (type.googleapis.com/google.protobuf.ListValue), 2.007"}, {'field': 'data[0].values[9]', 'description': "Invalid value at 'data[0].values[9]' (type.googleapis.com/google.protobuf.ListValue), 2.055"}, {'field': 'data[0].values[10]', 'description': "Invalid value at 'data[0].values[10]' (type.googleapis.com/google.protobuf.ListValue), 2.103"}, {'field': 'data[0].values[11]', 'description': "Invalid value at 'data[0].values[11]' (type.googleapis.com/google.protobuf.ListValue), 2.15"}, {'field': 'data[0].values[12]', 'description': "Invalid value at 'data[0].values[12]' (type.googleapis.com/google.protobuf.ListValue), 2.198"}, {'field': 'data[0].values[13]', 'description': "Invalid value at 'data[0].values[13]' (type.googleapis.com/google.protobuf.ListValue), 2.302"}, {'field': 'data[0].values[14]', 'description': "Invalid value at 'data[0].values[14]' (type.googleapis.com/google.protobuf.ListValue), 2.349"}, {'field': 'data[0].values[15]', 'description': "Invalid value at 'data[0].values[15]' (type.googleapis.com/google.protobuf.ListValue), 2.359"}, {'field': 'data[0].values[16]', 'description': "Invalid value at 'data[0].values[16]' (type.googleapis.com/google.protobuf.ListValue), 2.406"}, {'field': 'data[0].values[17]', 'description': "Invalid value at 'data[0].values[17]' (type.googleapis.com/google.protobuf.ListValue), 2.406"}]}]}
我找不到关于这个问题的任何东西。我知道这不是范围的错,数组本身似乎也是有效的。
1条答案
按热度按时间wqlqzqxt1#
虽然我不知道我是否能正确理解你现在的问题,下面的修改如何?
发件人:
收件人:
strengths_1
可能是一个一维数组。在这种情况下,它需要是一个二维数组。strengths_1
的值从“D3”开始作为行方向。strengths_1
的示例值?我想通过这个来证实这一点。参考: