ManojPrabhakaran
ManojPrabhakaran

Reputation: 13

importing google.cloud.datastore not working

I am working in pycharm(in windows) environment.

I am building a website to send query to datastore and display values. I also have data under kind="SpecialTest" that is automatically saved through Node.js. Now I wanted to Query the data from Python.

I installed google-cloud-datastore from command line.

But I can't establish connection to datastore.

My code:

from google.cloud import datastore
cli=datastore.Client(project="My_project_I")
query4= cli.query(kind="SpecialTest").order('Published_at')
print query4

My result:

Internal Server Error

The server has either erred or is incapable of performing the requested operation.

Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1272, in default_dispatcher
    self.handlers[handler] = handler = import_string(handler)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1850, in import_string
    return getattr(__import__(module, None, None, [obj]), obj)
  File "C:\Users\Harry\workspace\www\app\account.py", line 11, in <module>
    from google.cloud import datastore
  File "C:\Python27\lib\site-packages\google\cloud\datastore\__init__.py", line 60, in <module>
    from google.cloud.datastore.batch import Batch
  File "C:\Python27\lib\site-packages\google\cloud\datastore\batch.py", line 24, in <module>
    from google.cloud.datastore import helpers
  File "C:\Python27\lib\site-packages\google\cloud\datastore\helpers.py", line 23, in <module>
    from google.protobuf import struct_pb2
ImportStringError: import_string() failed for 'app.account.UserAccount'. Possible reasons are:

- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;

Original exception:

ImportError: No module named protobuf

Debugged import:

- 'app' found in 'C:\\Users\\Harry\\workspace\\www\\app\\__init__.pyc'.
- 'app.account' not found.

Upvotes: 1

Views: 769

Answers (1)

Dan Cornilescu
Dan Cornilescu

Reputation: 39814

The datastore client library is not supplied by GAE, you need to install/vendor it into your application (different method than for a standalone script).

Alternatively you can use the GAE-specific datastore library - it's actually recommended as it offers some advantages over the general purpose one. From Google App Engine Standard Environment Client Libraries:

Integrate Cloud Datastore with your App Engine Standard Environment applications by using the App Engine client libraries.

...

Python Google Datastore NDB Client Library

Note: For App Engine applications that are written in Python, the Google Datastore DB Client Library is no longer recommended; use the Google Datastore NDB Client Library instead.

Upvotes: 1

Related Questions