403权限不足或不足

时间:2018-10-10 10:10:43

标签: python django python-3.x google-cloud-platform google-cloud-datastore

我正在运行数据存储模拟器。当我运行“ dev_appserver.py app.yaml”命令时,出现此错误

  

403权限不足或不足。

这是我得到的警告。我知道身份验证有问题。我经历了this。但是最终找不到解决方法。

一些细节:

  1. 我正在为某些应用程序使用MySQL数据库。

  2. 对于其他人,我想使用数据存储。

  3. 我在一个选项卡上运行数据存储模拟器,在另一个选项卡上运行Google云代理,在第三个选项卡上运行dev_appserver。

  4. 我已经使用命令gcloud beta emulators数据存储区env-init设置了环境变量。

我的settings.py

if os.getenv('GAE_APPLICATION', None):
# Running on production App Engine, so connect to Google Cloud SQL using
# the unix socket at /cloudsql/<your-cloudsql-connection string>
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '/cloudsql/connectionname',
        'NAME': 'db_name',
        'USER': 'username',
        'PASSWORD': 'password',
    }
}
else:
# Running locally so connect to either a local MySQL instance or connect to
# Cloud SQL via the proxy. To start the proxy via command line:
#
#     $ cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306
#
# See https://cloud.google.com/sql/docs/mysql-connect-proxy
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '127.0.0.1',
        'PORT': '3307',
        'NAME': 'dbname',
        'USER': 'username',
        'PASSWORD': 'password',
    }
}    
# [END db_setup]

我的app.yaml

runtime: python37

handlers:
- url: /static
  static_dir: static/
- url: /.*
  script: auto

技术背景:

Django 2.1 Python 3.5.2

堆栈跟踪:

Traceback (most recent call last):
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/django/core/handlers/base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/salman/chaipani_env/project_chaipani/chaipani/views.py", line 20, in post_new
    post = models.insert(data)
  File "/home/salman/chaipani_env/project_chaipani/chaipani/models.py", line 15, in insert
    client.put(entity)
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/cloud/datastore/client.py", line 404, in put
    self.put_multi(entities=[entity])
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/cloud/datastore/client.py", line 431, in put_multi
    current.commit()
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/cloud/datastore/batch.py", line 273, in commit
    self._commit()
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/cloud/datastore/batch.py", line 249, in _commit
    self.project, mode, self._mutations, transaction=self._id)
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/cloud/datastore_v1/gapic/datastore_client.py", line 426, in commit
    request, retry=retry, timeout=timeout, metadata=metadata)
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/api_core/gapic_v1/method.py", line 139, in __call__
    return wrapped_func(*args, **kwargs)
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/api_core/retry.py", line 260, in retry_wrapped_func
    on_error=on_error,
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/api_core/retry.py", line 177, in retry_target
    return target()
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/api_core/timeout.py", line 206, in func_with_timeout
    return func(*args, **kwargs)
  File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/api_core/grpc_helpers.py", line 61, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.PermissionDenied: 403 Missing or insufficient permissions.
INFO     2018-10-10 10:51:26,298 module.py:880] default: "POST /users/post/new/ HTTP/1.1" 500 133823

1 个答案:

答案 0 :(得分:0)

您的默认服务帐户似乎没有足够的权限。可能需要一些其他权限,例如“ Datastore Index Admin”才能推断出Datastore [1]。我不确定这在Datastore仿真器中如何工作,但是由于它旨在提供本地仿真,因此也许它将获得执行测试的角色和权限。您能否检查您的服务帐户中的权限[2],是否需要进行更改,如果问题仍然存在,请通知我。我将等待您的答复。

[1] https://cloud.google.com/appengine/docs/flexible/nodejs/granting-project-access#before_you_begin [2] https://cloud.google.com/iam/docs/granting-roles-to-service-accounts