Google Maps Engine API Client Library for Python to create a table asset

1 view
Skip to first unread message

Bprodz via StackOverflow

unread,
Oct 20, 2014, 12:11:16 PM10/20/14
to google-appengin...@googlegroups.com

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?



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/26470060/google-maps-engine-api-client-library-for-python-to-create-a-table-asset

Lukasz Tracewski via StackOverflow

unread,
Oct 26, 2014, 7:09:24 AM10/26/14
to google-appengin...@googlegroups.com

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:

  1. body = json.loads(body), which will create a dictionary for you or
  2. Pass body directly to the create method, making sure that it is a proper dictionary

One 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.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/26470060/google-maps-engine-api-client-library-for-python-to-create-a-table-asset/26572290#26572290
Reply all
Reply to author
Forward
0 new messages