【问题标题】:error occurred while trying to write emails to google sheet尝试将电子邮件写入 Google 表格时发生错误
【发布时间】:2020-09-01 22:52:16
【问题描述】:
import gspread

emails = ['test@test.com' , 'test1@test1.com']


def api(key):
    gc = gspread.service_account(filename='Auth.json')
    sh = gc.open_by_key(key)
    worksheet = sh.get_worksheet(1)
    worksheet.insert_row(["Emails"], 1)
    worksheet.insert_rows(emails, 2)


api("myapi")

错误: 我无法将电子邮件列表写入 google sheet 行,因为我不断收到以下错误:

gspread.exceptions.APIError: {'code': 400, 'message': 'Invalid value at \'data.values[0]\' (type.googleapis.com/google.protobuf.ListValue), "test@test.com"\nInvalid value at \'data.values[1]\' (type.googleapis.com/google.protobuf.ListValue), "test1@test1.com"', 'status': 'INVALID_ARGUMENT', 'details': [{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'data.values[0]', 'description': 'Invalid value at \'data.values[0]\' (type.googleapis.com/google.protobuf.ListValue), "test@test.com"'}, {'field': 'data.values[1]', 'description': 'Invalid value at \'data.values[1]\' (type.googleapis.com/google.protobuf.ListValue), "test1@test1.com"'}]}]}

【问题讨论】:

    标签: python google-sheets google-sheets-api gspread


    【解决方案1】:

    我相信你的目标如下。

    • 您想将['test@test.com' , 'test1@test1.com'] 的值放入插入的行中。

    在这种情况下,我认为在这种情况下,['test@test.com' , 'test1@test1.com'] 必须是像[['test@test.com'], ['test1@test1.com']] 这样的二维数组。我认为错误的原因是由于这个。所以请修改如下,再测试一下。

    发件人:

    emails = ['test@test.com' , 'test1@test1.com']
    

    收件人:

    emails = [['test@test.com'], ['test1@test1.com']]
    

    参考资料:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-30
      • 2012-08-23
      • 1970-01-01
      • 2014-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多