gsheets 使用 batchupdate 插入 python 字典
gsheets inserting python dictonary using batchupdate
我是 gheets 的新手,正在寻找一种方法来将我抓取的数据插入到当前位于 python 字典中的 gheets 中。我想在批处理过程中执行此操作,以便我的蜘蛛程序可以一次更新多个字段。
{'page_url': 'https://www.websiteurl.com', 'company': 'my company', 'location': 'The Netherlands',
'price_excl_vat': '30000'}
我尝试构建一个 json 请求,但收到类型错误:无法散列的类型:'dict'。我知道它是因为数据字段采用字符串,但认为 qould 能够采用字典但似乎无法找到如何做。一整天都在这样做,似乎无法弄清楚我做错了什么。
batch_update_spreadsheet_request_body = {
{
"requests": [
{
"insertRange": {
"range": {
"sheetId": '12345tutu',
},
}
},
{
"pasteData": {
"data": {'page_url': 'https://www.websiteurl.com', 'company': 'my company', 'location': 'The Netherlands',
'price_excl_vat': '30000'},
}
}
]
}
}
request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body=batch_update_spreadsheet_request_body)
response = request.execute()
你应该删除一对 {}
:
batch_update_spreadsheet_request_body = {
"requests": [
{
"insertRange": {
"range": {
"sheetId": '12345tutu',
},
}
},
{
"pasteData": {
"data": {'page_url': 'https://www.websiteurl.com', 'company': 'my company', 'location': 'The Netherlands',
'price_excl_vat': '30000'},
}
}
]
}
它创建了一个包含字典的集合,但这是不可能的,因为正如错误所说,集合元素必须是可哈希的,而字典不是。
我是 gheets 的新手,正在寻找一种方法来将我抓取的数据插入到当前位于 python 字典中的 gheets 中。我想在批处理过程中执行此操作,以便我的蜘蛛程序可以一次更新多个字段。
{'page_url': 'https://www.websiteurl.com', 'company': 'my company', 'location': 'The Netherlands',
'price_excl_vat': '30000'}
我尝试构建一个 json 请求,但收到类型错误:无法散列的类型:'dict'。我知道它是因为数据字段采用字符串,但认为 qould 能够采用字典但似乎无法找到如何做。一整天都在这样做,似乎无法弄清楚我做错了什么。
batch_update_spreadsheet_request_body = {
{
"requests": [
{
"insertRange": {
"range": {
"sheetId": '12345tutu',
},
}
},
{
"pasteData": {
"data": {'page_url': 'https://www.websiteurl.com', 'company': 'my company', 'location': 'The Netherlands',
'price_excl_vat': '30000'},
}
}
]
}
}
request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body=batch_update_spreadsheet_request_body)
response = request.execute()
你应该删除一对 {}
:
batch_update_spreadsheet_request_body = {
"requests": [
{
"insertRange": {
"range": {
"sheetId": '12345tutu',
},
}
},
{
"pasteData": {
"data": {'page_url': 'https://www.websiteurl.com', 'company': 'my company', 'location': 'The Netherlands',
'price_excl_vat': '30000'},
}
}
]
}
它创建了一个包含字典的集合,但这是不可能的,因为正如错误所说,集合元素必须是可哈希的,而字典不是。