我是一個新手,試圖在標準 App 引擎上部署一個玩具 django 應用程式,但出現以下錯誤。
在本地運行應用程式
當我使用 127.0.0.1 或公共 IP 作為“HOST”地址時,我的應用程式使用云 SQL 在本地正常運行。但是,如果我像這樣使用 GCP 連接名稱,則會出現此錯誤:
'HOST': '/cloudsql/asim800:us-central1:django-mysql-1'
OperationalError: (2002, "Can't connect to local MySQL server through socket '/cloudsql/asim800:us-central1:django-mysql-1'
在 GAE 上運行應用程式
使用 HOST='/cloudsql/asim800:us-central1:django-mysql-1',我收到此錯誤 2003,“無法連接到 'localhost' 上的 MySQL 服務器([Errno 111] 連接被拒絕)” - 不確定為什么我在錯誤中收到“localhost”,但將 Google 連接名稱轉換為主機和埠資訊似乎有問題。
在 GAE 上為 mysql 實體使用公共 IP 會導致超時。
我的 settings.py 看起來像這樣
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/asim800:us-central1:django-mysql-1',
'NAME': 'myproject',
'USER': 'pblogsu',
'PASSWORD': '****',
}
}
我可以在以下日志中正確看到它們:
{'database': 'myproject', 'host': '/cloudsql/asim800:us-central1:django-app1', 'password': 'pblogsu', 'user': 'hidden'}
我已啟用 Google Cloud SQL API。不確定如何除錯 Google 連接名稱到主機/埠地址的映射。我看到過類似這里報告的類似問題(https://github.com/GoogleCloudPlatform/python-docs-samples/issues/870),但沒有任何建議對我有幫助。任何幫助將不勝感激。
PS:我已經大幅編輯了我的問題。早些時候我使用過 postgesql,結果非常相似。
uj5u.com熱心網友回復:
檢查引數unix_socket_directories和port在 PostgreSQL 服務器上。為您的連接嘗試作業
服務器必須與客戶端在同一臺機器上運行
cloudsql/asim800:us-central1:django-app1必須在unix_socket_directoriesport必須是 5432
uj5u.com熱心網友回復:
我終于能夠弄清楚需要在 IAM & Admin> IAM 中添加一個服務帳戶(與 GAE 關聯),然后賦予 Cloud sql.Client 角色。
事后看來,這聽起來很容易解決,但要解決這個問題需要花費大量精力。我懷疑可能存在權限問題,但我不確定需要添加哪個帳戶。在日志中看到此錯誤后,我得到了第一個線索:
"CloudSQL warning: your action is needed to update your application and avoid potential disruptions. Please see https://cloud.google.com/sql/docs/mysql/connect-overview for additional details: ensure that the account has access to "asim800:us-central1:django-mysql-1" (and make sure there's no typo in that name). Error during createEphemeral for asim800:us-central1:django-mysql-1: googleapi: Error 403: The client is not authorized to make this request., notAuthorized"
謝謝你的幫助。如果其他人遇到問題,我很樂意添加任何詳細資訊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/318988.html
上一篇:為什么npm給我這個輸出?
