I'm trying to use Google Maps Engine API Client Library for Python to create table object using the following code:
service = build('mapsengine', 'v1', developerKey=api_key, http=http)
table = service.tables()
request = table.create(body = body)
response = request.execute()
Where body is the following:
{
"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"
}
]
}
}
However, I get the error:
---------------------------------------------------------------------------
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.">
I've tried using body = json.dumps(body) but I still get the same error. The only argument which .create() takes in a body (docs) and I based the content of the body from this Google Maps Engine tutorial. On the Google Developers Console I can see that I've making requests to my project (although they've all resulted in errors). Could somebody explain what I've done wrong?
I had the same problem, in fact this is how I came across your question. Yes, the body looks fine, but only at the first sight:
body = {
"projectId" : "xxx",
"name": "API test 2",
"layerType": "image"
}
config = json.dumps(body)
print type(config)
Spoiler: it is a string!
Solution:
body = json.loads(body), which will create a dictionary for you orbody directly to the create method, making sure that it is a proper dictionaryOne more thing: it also seems that you are missing a mandatory parameter: layerType. Check the documentation for create method. I guess it will be vector in your case.