Python 用于插入和更新列的Google Fusion表API
我正在尝试更新现有的fusion表,就像在给定python中一样。它适用于方法GET,但不适用于方法PUT和POST。我的URL请求功能是:Python 用于插入和更新列的Google Fusion表API,python,google-api,google-fusion-tables,Python,Google Api,Google Fusion Tables,我正在尝试更新现有的fusion表,就像在给定python中一样。它适用于方法GET,但不适用于方法PUT和POST。我的URL请求功能是: mport urllib2, urllib, simplejson, sys, httplib def runRequest(method, url, data=None, headers=None): request = httplib.HTTPSConnection("www.googleapis.com") if data and
mport urllib2, urllib, simplejson, sys, httplib
def runRequest(method, url, data=None, headers=None):
request = httplib.HTTPSConnection("www.googleapis.com")
if data and headers:
request.request(method, url, data, headers)
else:
request.request(method, url)
response = request.getresponse()
response = response.read()
return response
我定义
getColumns和InsertColumns作为:
getColumn方法看起来不错:
GET COLUMNS
200 OK
{ "kind": "fusiontables#columnList",
"totalItems": 28, "items": [ { "kind": "fusiontables#column",
"columnId": 0, "name": "VDC", "type": "STRING",
"formatPattern": "NONE", "validateData": false }}
我从insertColumn方法中得到以下错误:
Insert Column
400 Bad Request
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
我认为这是由于错误的runRequest方法或httpconnection工作不好造成的。你对此有什么建议吗?。有没有别的办法解决这个问题?。谢谢。错误消息是一个很好的开始 解析错误 如果您实际检查数据输出,您会发现它不是有效的JSON
tableid, name, data_type = ('foo', 'bar', 'baz')
data = '''{
"tableId": %s,
"name": %s,
"type":%s
}''' % (tableid, name, data_type)
print data
"{
tableId:foo,
姓名:bar,,
类型:baz
}"
字符串值周围需要有引号。更好的版本应该是这样的
tableid, name, data_type = ('foo', 'bar', 'baz')
data = {
"tableId": tableid,
"name": name,
"type": data_type
}
print simplejson.dumps(data)
{type:baz,tableId:foo,name:bar}
tableid, name, data_type = ('foo', 'bar', 'baz')
data = {
"tableId": tableid,
"name": name,
"type": data_type
}
print simplejson.dumps(data)