pythonで読み取ったQRコードの内容をGoogleスプレットシートに書き込むことができません。
python
1from pyzbar.pyzbar import decode 2from PIL import Image 3from oauth2client.service_account import ServiceAccountCredentials 4from httplib2 import Http 5import gspread 6import datetime 7from datetime import datetime 8import os 9from pyzbar.pyzbar import decode 10from pyzbar.pyzbar import ZBarSymbol 11import cv2 12import numpy as np 13import json 14 15scopes = ['https://spreadsheets.google.com/feeds', 16 'https://www.googleapis.com/auth/drive'] 17json_file = r'C:\Users*******\Downloads\face-id-022a16cbf2d0.json' 18credentials = ServiceAccountCredentials.from_json_keyfile_name(json_file, scopes=scopes) 19http_auth = credentials.authorize(Http()) 20 21doc_id = '*********' 22SPREADSHEET_KEY = '**********' 23client = gspread.authorize(credentials) 24gfile = client.open_by_key(doc_id) 25gc = gspread.authorize(credentials) 26worksheet = gfile.sheet1 27 28worksheet = gc.open_by_key(SPREADSHEET_KEY).sheet1 29 30 31 32 33 34 35img = cv2.imread(r'C:\Users*******\Pictures\qrcode_testqr.png') 36 37# データ、検出領域の四隅の座標、QRコードのバージョン情報を取得 38qr = cv2.QRCodeDetector() 39data, points, straight_qrcode = qr.detectAndDecode(img) 40 41print('データ:', data) 42print("バージョン:", ((straight_qrcode.shape[0] - 21) / 4) + 1) 43 44worksheet.append_row(data)
Traceback (most recent call last): File "API_qrdecode.py", line 50, in <module> worksheet.append_row(data) File "C:\Users\HN4-00012\AppData\Local\Programs\Python\Python37-32\lib\site-packages\gspread\models.py", line 702, in append_row return self.spreadsheet.values_append(self.title, params, body) File "C:\Users\HN4-00012\AppData\Local\Programs\Python\Python37-32\lib\site-packages\gspread\models.py", line 100, in values_append r = self.client.request('post', url, params=params, json=body) File "C:\Users\HN4-00012\AppData\Local\Programs\Python\Python37-32\lib\site-packages\gspread\client.py", line 79, in request raise APIError(response) gspread.exceptions.APIError: { "error": { "code": 400, "message": "Invalid value at 'data.values[0]' (type.googleapis.com/google.protobuf.ListValue), \"hiroaki\"", "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), \"hiroaki\"" } ] } ] } }
回答1件
あなたの回答
tips
プレビュー