我正在尝试使用Google Spreadsheets OAuth和gspread库。发送凭据时,我收到// this will store our valid fields
var validFields = [];
$("form").parsley();
// whenever a field is valid
$.listen('parsley:field:success', function (parsleyField) {
// add this field's name to the array
addToArray(parsleyField.$element.attr('name'));
// Do we have both fields within the array?
if ($.inArray('field1', validFields) != -1 && $.inArray('field2', validFields) != -1) {
// If so, remove the class
$(".tab-nav-1").removeClass("tab-validation-error");
} else {
// Otherwise, add the class. There could be a time
$(".tab-nav-1").addClass("tab-validation-error");
}
});
// Whenever an error occurs, lets remove the field from the array
$.listen('parsley:field:error', function (parsleyField) {
removeFromArray(parsleyField.$element.attr('name'));
});
/**
* Adds a string to an array
*/
function addToArray(fieldName) {
// For our case, we're just adding the value if it matches our fields
if ($.inArray(fieldName, validFields) === -1 && (fieldName == 'field1' || fieldName == 'field2')) {
validFields.push(fieldName);
}
}
/**
* Removes a string from an array
*/
function removeFromArray(fieldName) {
// For this case, we discard the fields that don't match the fields we need
if (fieldName != 'field1' && fieldName != 'field2')
return;
// So, add the field if it doesn't exist in the array
if ($.inArray(fieldName, validFields) != -1) {
for(var i = validFields.length - 1; i >= 0; i--) {
validFields.splice(i, 1);
}
}
}
个异常。我该如何解决这个问题?
TypeError: expected bytes, not str
import gspread
import json
from oauth2client.client import SignedJwtAssertionCredentials
json_key = json.load(open('Test for gspread-78c678a7fb15.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)
答案 0 :(得分:1)
密钥是一个字符串,需要编码为字节。将credentials =
替换为以下内容:
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'].encode(), scope)