我正在尝试使用适用于Python的Google Maps Engine API客户端库通过以下代码创建表对象:
service = build('mapsengine', 'v1', developerKey=api_key, http=http)
table = service.tables()
request = table.create(body = body)
response = request.execute()
body
以下是哪里:
{
"projectId": "deletedProjectID",
"name": "turf zones of Uppsala ",
"description": "Table to contain zones to plot",
"tags": [
"turf", "turfing", "uppsala"
],
"schema": {
"columns": [
{
"name": "dateCreated",
"type": "points"
},
{
"name": "latitude",
"type": "points"
},
{
"name": "longitude",
"type": "points"
},
{
"name": "name",
"type": "points"
}
]
}
}
但是,我得到了错误:
---------------------------------------------------------------------------
HttpError Traceback (most recent call last)
<ipython-input-76-698f94a34d91> in <module>()
----> 1 response = request.execute()
C:\Users\User\AppData\Local\Enthought\Canopy32\User\lib\site-packages\oauth2client\util.pyc in positional_wrapper(*args, **kwargs)
130 else: # IGNORE
131 pass
--> 132 return wrapped(*args, **kwargs)
133 return positional_wrapper
134
C:\Users\User\AppData\Local\Enthought\Canopy32\User\lib\site-packages\apiclient\http.pyc in execute(self, http, num_retries)
721 callback(resp)
722 if resp.status >= 300:
--> 723 raise HttpError(resp, content, uri=self.uri)
724 return self.postproc(resp, content)
725
HttpError: <HttpError 400 when requesting https://www.googleapis.com/mapsengine/v1/tables?alt=json&key=[deleted] returned "A value is required.">
我尝试使用,body = json.dumps(body)
但仍然遇到相同的错误。唯一.create()
包含主体(docs)的参数,我基于此Google Maps Engine教程中的主体内容。在Google Developers Console上,我可以看到我正在向我的项目提出请求(尽管它们都导致了错误)。有人可以解释我做错了什么吗?
我遇到了同样的问题,实际上这就是我遇到您的问题的方式。是的,body
看起来不错,但只有乍一看:
body = {
"projectId" : "xxx",
"name": "API test 2",
"layerType": "image"
}
config = json.dumps(body)
print type(config)
剧透:这是一个字符串!
解决方案:
body = json.loads(body)
,这将为您创建字典或body
直接传递给create
方法,确保它是正确的字典还有一件事:似乎还缺少必填参数:layerType
。检查文档中的create方法。我想这将vector
在您的情况下。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句