尝试将电子邮件写入Google工作表时发生错误 [英] error occurred while trying to write emails to google sheet

查看:246
本文介绍了尝试将电子邮件写入Google工作表时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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工作表行:

Error: I'm unable to write list of emails to google sheet rows as i keep getting the following error:

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"'}]}]}

推荐答案

我相信您的目标如下.

  • 您要将['test@test.com' , 'test1@test1.com']的值放入插入的行中.
  • You want to put the values of ['test@test.com' , 'test1@test1.com'] to the inserted rows.

在这种情况下,我认为在这种情况下,['test@test.com' , 'test1@test1.com']必须是像[['test@test.com'], ['test1@test1.com']]这样的二维数组.我认为错误的原因是由于此.因此,请进行如下修改,然后再次进行测试.

In this case, I think that in this case, ['test@test.com' , 'test1@test1.com'] is required to be 2 dimensional array like [['test@test.com'], ['test1@test1.com']]. I think that the reason of error is due to this. So please modify as follows, and test it again.

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

收件人:

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

参考文献:

  • insert_rows
  • References:

    • insert_rows
    • 这篇关于尝试将电子邮件写入Google工作表时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆