数据存储区客户端query.fetch()引发错误

时间:2018-10-03 03:43:54

标签: python google-app-engine google-cloud-platform google-cloud-datastore

尝试在Users表中创建新条目时遇到此异常。当前Users表是空的。基本上我正在查询数据存储的类型,如果记录存在。由于某种原因,它在下面的代码行引发异常

result = list(query.fetch())

完整代码

 class User(object):

    __tablename__ = "Users"

   def __init__(self, data, admin=False):
    bcrypt = Bcrypt()
    self.email = data.get('email'),
    self.password = bcrypt.generate_password_hash(
        data.get('email'), 12
    ).decode()
    self.is_admin = admin
    self.firstname = "FirstName"
    self.middlename = "LastName"
    self.address = "address"
    self.is_active = True
    self.ds = datastore.Client()

  def create(self):
    """
    Create User
    :return: string
    """

    logger.log_text("create user request ")
    logger.log_text('email {}'.format(self.email))
    query = self.ds.query(kind=self.__tablename__)
    query.add_filter('email', '=', self.email)
    result = list(query.fetch())
    if result:
        logger.log_text('list {}'.format(result))
    else:
        key = self.ds.key('user')
        logger.log_text(key)
        entity = datastore.Entity(
            key=key)
        entity.update({
            'email': self.email,
            'password': self.password,
            'registered_on': datetime.now().isoformat(),
            'is_admin': self.is_admin,
            'created_date': datetime.now().isoformat()})
        self.ds.put(entity)

错误:

  raise ValueError('Unknown protobuf attr type', type(val))
  ValueError: ('Unknown protobuf attr type', <class 'tuple'>)
  "  

完整的错误详细信息:

File "/env/lib/python3.6/site-packages/flask/app.py", line 1982, in 
       wsgi_app
 response = self.full_dispatch_request()
File "/env/lib/python3.6/site-packages/flask/app.py", line 1614, in 
    full_dispatch_request
rv = self.handle_user_exception(e)
File "/env/lib/python3.6/site-packages/flask/app.py", line 1517, in 
     handle_user_exception
    reraise(exc_type, exc_value, tb)
File "/env/lib/python3.6/site-packages/flask/_compat.py", line 33, in 
     reraise
    raise value
File "/env/lib/python3.6/site-packages/flask/app.py", line 1612, in 
   full_dispatch_request
rv = self.dispatch_request()
File "/env/lib/python3.6/site-packages/flask/app.py", line 1598, in 
    dispatch_request
   return self.view_functions[rule.endpoint](**req.view_args)
File "/home/vmagent/app/internal/user/user.py", line 13, in CreateUser
   return usrmgr.CreateUser(post_data)
File "/home/vmagent/app/internal/user/usermanager.py", line 14, in 
CreateUser
user.create()
File "/home/vmagent/app/internal/user/models.py", line 34, in create
result = list(query.fetch())
File "/env/lib/python3.6/site- 
packages/google/api_core/page_iterator.py", line 199, in _items_iter
for page in self._page_iter(increment=False):
File "/env/lib/python3.6/site- 
packages/google/api_core/page_iterator.py", line 230, in _page_iter
page = self._next_page()
File "/env/lib/python3.6/site- 
packages/google/cloud/datastore/query.py", line 500, in _next_page
query_pb = self._build_protobuf()
File "/env/lib/python3.6/site- 
packages/google/cloud/datastore/query.py", line 442, in _build_protobuf
pb = _pb_from_query(self._query)
File "/env/lib/python3.6/site-
packages/google/cloud/datastore/query.py", line 565, in _pb_from_query
helpers._set_protobuf_value(property_filter.value, value)
File "/env/lib/python3.6/site- 
packages/google/cloud/datastore/helpers.py", line 447, in 
_set_protobuf_value
attr, val = _pb_attr_value(val)
File "/env/lib/python3.6/site- 
packages/google/cloud/datastore/helpers.py", line 364, in 
_pb_attr_value
raise ValueError('Unknown protobuf attr type', type(val))
ValueError: ('Unknown protobuf attr type', <class 'tuple'>)
"  

1 个答案:

答案 0 :(得分:0)

键入此代码以获取数据。

result=list(query.fetchall())