我正在Google App Engine與Datastore.
這是我的模型類project_name/model/quiz_models.py
from google.appengine.ext import db
class Quiz(db.Model):
quiz_id = db.StringProperty()
post_id = db.StringProperty()
creator_id = db.StringProperty()
timestamp = db.DateTimeProperty()
quiz_title = db.StringProperty()
main.py 檔案
@app.route('/insert_db')
def run_quickstart():
quiz = Quiz(post_id=data['post_id'],
quiz_id='123',
quiz_info='test info',
creator_id=data['creator_id'],
timestamp=datetime.datetime.now(),
quiz_title='Test title')
quiz.put()
我什么時候向/insert_dbURL發出 get 請求我收到此錯誤
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/appengine/api/apiproxy_stub_map.py", line 69, in CreateRPC
assert stub, 'No api proxy found for service "%s"' % service AssertionError: No api proxy found for service "datastore_v3"
但是谷歌提供的這個示例片段作業正常
@app.route('/insert_db')
def run_quickstart():
# [START datastore_quickstart]
# Imports the Google Cloud client library
# Instantiates a client
datastore_client = datastore.Client()
# The kind for the new entity
kind = "Tasker"
# The name/ID for the new entity
name = "sampletask1aa"
# The Cloud Datastore key for the new entity
task_key = datastore_client.key(kind, name)
# Prepares the new entity
task = datastore.Entity(key=task_key)
task.update(
{
"category": "Personal",
"done": False,
"priority": 4,
"description": "Cloud Datastore",
}
)
# Saves the entity
datastore_client.put(task)
uj5u.com熱心網友回復:
有多種方式可以與來自 GAE 的資料存盤進行互動。許多選項使它非常混亂,但我會盡力為您指明正確的方向。
您的代碼正在使用非常舊的資料存盤訪問技術,如以下行所示:
from google.appengine.ext import db
這是帶有 Python 2 的原始第一代 GAE。我懷疑它不可能與 Python 3 一起使用。
從您的代碼來看,您似乎希望在 Python 3 中使用第二代 GAE(這很好,因為舊的東西正在被淘汰)。您有兩個主要的資料存盤選項:
- 使用了
google-cloud-datastorePython客戶機。這就是上面的作業代碼示例所使用的。 - 使用了
google-cloud-ndbPython客戶機。這更接近db代碼中的舊庫。
如果您正在開始一個新專案,那么第一個選擇會更好。如果您正在遷移 Python 2 專案,那么第二個選擇可能更好。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/318960.html
標籤:谷歌应用引擎 谷歌云平台 谷歌云数据存储 谷歌应用引擎蟒蛇
