使用batchupd插入python命令的gsheets

2024-09-29 21:26:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我对gheets是个新手,正在寻找一种方法,将我搜集到的数据插入到当前python字典中的gheets中。我想在批处理过程中这样做,这样我的蜘蛛可以一次更新多个字段。你知道吗

{'page_url': 'https://www.websiteurl.com', 'company': 'my company', 'location': 'The Netherlands',
                  'price_excl_vat': '30000'}

我试图构建一个json请求,但得到TypeError:unhable type:'dict'。我知道这是因为数据字段需要一个字符串,但是我想我可以用一个字典,而且似乎找不到怎么做。一整天都在这样,似乎不知道我做错了什么。你知道吗

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()

Tags: thehttpscomurl字典requestmywww
1条回答
网友
1楼 · 发布于 2024-09-29 21:26:33

您应该删除一对{}

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'},

       }
      }
     ]
    }

它创建了一个包含dictionary的集合,这是不可能的,因为正如错误所说,set元素必须是可哈希的,而dict则不是。你知道吗

相关问题 更多 >

    热门问题