Description
Page Name: index
Release: 0.12.0
I'm just trying to get the example code on the gcloud-python homepage (http://googlecloudplatform.github.io/gcloud-python/) or getting started page (http://googlecloudplatform.github.io/gcloud-python/stable/index.html) to work.
Setup:
I created an n1-standard-1 machine in us-central1-f using the latest ubuntu 1510 image and including the datastore scope. All I've run on it (as root):
apt-get update
apt-get installed python-pip python-crypto python-openssl
pip install gcloud
I then logged in via my usual user account and ran the interactive python interpreter. First, I tried the homepage example code:
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gcloud import datastore
>>>
>>> client = datastore.Client()
>>> product_key = client.key('Product', 123)
>>> print(client.get(product_key))
None
then, the getting started example code:
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gcloud import datastore
>>>
>>> client = datastore.Client()
>>> key = client.key('Person')
>>>
>>> entity = datastore.Entity(key=key)
>>> entity['name'] = 'Your name'
>>> entity['age'] = 25
>>> client.put(entity)
This pauses, like it has successfully put, but I can't retrieve?
>>> client.get(key)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/client.py", line 250, in get
deferred=deferred)
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/client.py", line 291, in get_multi
transaction_id=transaction and transaction.id,
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/client.py", line 123, in _extended_lookup
transaction_id=transaction_id,
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py", line 199, in lookup
_datastore_pb2.LookupResponse)
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py", line 117, in _rpc
data=request_pb.SerializeToString())
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py", line 94, in _request
raise make_exception(headers, error_status.message, use_json=False)
gcloud.exceptions.BadRequest: 400 Key path element must not be incomplete: [Person: ]
However, if I combine the two code examples, it works:
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gcloud import datastore
>>>
>>> client = datastore.Client()
>>> key = client.key('Person', 123)
>>>
>>> entity = datastore.Entity(key=key)
>>> entity['name'] = 'Your name'
>>> entity['age'] = 25
>>> client.put(entity)
>>> print(client.get(key))
<Entity[{'kind': u'Person', 'id': 123L}] {u'age': 25L, u'name': 'Your name'}>
So, probably need to update one/both of these to be functional for new users?