4

我是Google雲端平臺新手。我已經建立了一個Google VM實例。我本地計算機上面臨的一個身份驗證問題運行命令時:gcloud.exceptions.Forbidden:403權限缺失或不足

python manage.py makemigrations

能否請您提出一些提示/步驟來解決一樣嗎?

錯誤跟蹤

File "/constants.py", line 18, in <module> 
    table_data = datastore_fetch(project_id, entity_kind) 
    File "/datastore_helper.py", line 23, in datastore_fetch 
    results = list(query.fetch()) 
    File "/venv/local/lib/python2.7/site-packages/gcloud/datastore/query.py", line 463, in __iter__ 
    self.next_page() 
    File "/venv/local/lib/python2.7/site-packages/gcloud/datastore/query.py", line 434, in next_page 
    transaction_id=transaction and transaction.id, 
    File "/venv/local/lib/python2.7/site-packages/gcloud/datastore/connection.py", line 286, in run_query 
    _datastore_pb2.RunQueryResponse) 
    File "/venv/local/lib/python2.7/site-packages/gcloud/datastore/connection.py", line 124, in _rpc 
    data=request_pb.SerializeToString()) 
    File "/venv/local/lib/python2.7/site-packages/gcloud/datastore/connection.py", line 98, in _request 
    raise make_exception(headers, error_status.message, use_json=False) 
gcloud.exceptions.Forbidden: 403 Missing or insufficient permissions. 

其他信息:

gcloud auth list 
Credentialed Accounts: 
- [email protected] ACTIVE 
To set the active account, run: 
    $ gcloud config set account `ACCOUNT` 

gcloud config list 
Your active configuration is: [default] 

[core] 
account = [email protected] 
disable_usage_reporting = True 
project = user_project 

輸入:(獨立的Python功能)

from gcloud import datastore 
client = datastore.Client('user_project') 

print(vars(client.connection.credentials)) 

輸出:

{'scopes': set([]), 'revoke_uri': 'https://accounts.google.com/o/oauth2/revoke', 'access_token': None, 'token_uri': 'https://www.googleapis.com/oauth2/v4/token', 'token_info_uri': None, 'token_response': None, 'invalid': False, 'refresh_token': u'1/t-V_pZicXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'client_id': u'3XXXXXXXX9.apps.googleusercontent.com', 'id_token': None, 'client_secret': u'ZXXXXXXXXXXXXXXXXXXX2', 'token_expiry': None, 'store': None, 'user_agent': 'Python client library'} 

VM詳細

Firewalls 
Allow HTTP traffic 
Allow HTTPS traffic 

Availability policies 
Preemptibility Off (recommended) 

Automatic restart 
On (recommended) 

On host maintenance 
Migrate VM instance (recommended) 

Custom metadata 
None 

SSH Keys 
Block project-wide SSH keys 
None 

Service account 
[email protected]_project.iam.gserviceaccount.com 

Cloud API access scopes 
This instance has full API access to all Google Cloud services. 

感謝,

+0

有何建議? – Naveen

回答

2

剛跑到這兩個命令:

1. gcloud beta auth application-default login 
2. export GOOGLE_APPLICATION_CREDENTIALS='/<path_to_json>/client_secrets.json' 

從本地機器,並開始工作。

+1

很高興它的工作,但你不應該設置它。如果您運行'gcloud auth application-default login',然後取消設置'GOOGLE_APPLICATION_CREDENTIALS',會發生什麼情況? –

+0

我實際上從本地機器上運行了這兩個命令。 – Naveen

+0

對於Windows:'set GOOGLE_APPLICATION_CREDENTIALS = keyfile.json' – Beginner

8

應用默認憑據行爲在gcloudchanged自128

一個版本應該使用

gcloud auth application-default login 

代替。

請注意,通過gcloud auth logingcloud initgcloud config set account MY_ACCOUNT更改憑據不會影響應用程序默認憑據,它們與gcloud憑證分開管理。

相關問題