我正在尝试保存两条记录,然后获得第二条记录.问题是过滤器似乎不起作用.虽然我按名称("安德鲁W")过滤,但我总是得到"Joe Citizen".计数器还指示2个记录,它应该只是一个.这让我发疯了.请参阅下面的完整代码.结果打印出来counter 2 e2 {"Joe Citizen" "Manager" "2015-03-24 09:08:58.363929 +0000 UTC" ""}
package main
import (
"fmt"
"time"
"net/http"
"google.golang.org/appengine"
"google.golang.org/appengine/datastore"
)
type Employee struct {
Name string
Role string
HireDate time.Time
Account string
}
func init(){
http.HandleFunc("/", handle)
}
func handle(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
e1 := Employee{
Name: "Joe Citizen",
Role: "Manager",
HireDate: time.Now(),
}
_, err := datastore.Put(c, datastore.NewKey(c, "employee", "", 0, nil), &e1)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
panic(err) …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种每天导出 Cloud Datastore 并将其导入 BigQuery 的方法。手动方式在google page 中有描述。我没有找到一种干净的方法来自动化它。
阅读了有关Google数据存储区的概念/理论后,我开始使用Go数据存储区包
场景:种类User和LinkedAccount要求每个用户都有一个或多个关联账户(耶第三方登录)。为了保持高度一致性,LinkedAccounts将是关联用户的子级。然后,创建新用户涉及创建一个User和一个LinkedAccount,而不仅仅是一个。
用户创建似乎是交易的完美用例。如果说LinkedAccount创建失败,则事务回滚失败。目前看来这不可能。目标是在事务中创建父级,然后创建子级。
根据文档
如果事务是单个组事务,则事务中的所有数据存储区操作必须在同一实体组中的实体上进行操作
我们希望有一个新的User并且LinkedAccount要在同一个组中,所以对我来说,Datastore应该支持这种情况。我担心的是预期的含义是可以在单个事务中执行对同一组中现有实体的操作。
tx, err := datastore.NewTransaction(ctx)
if err != nil {
return err
}
incompleteUserKey := datastore.NewIncompleteKey(ctx, "User", nil)
pendingKey, err := tx.Put(incompleteUserKey, user)
if err != nil {
return err
}
incompleteLinkedAccountKey := datastore.NewIncompleteKey(ctx, "GithubAccount", incompleteUserKey)
// also tried PendingKey as parent, but its a separate struct type
_, err = tx.Put(incompleteLinkedAccountKey, linkedAccount)
if err != nil {
return err
}
// attempt to …Run Code Online (Sandbox Code Playgroud) 在过去48小时左右,我的小python GAE应用程序已经开始从ndb.get_multi调用获取AssertionErrors.
将附加完整的回溯,并且在/base/data/.../ndb/model.py的第734行的_BaseValue的__init__中生成服务器上生成错误,并且失败的断言是b_val不是None,并且消息"Can not not包装无"
该错误似乎与特定实体或实体无关,但到目前为止我只看到过一种实体类型(尚未测试其他实体).
get_multi调用仅适用于十几个键,并且错误是间歇性的,因此重复它有时会成功.或不...
我没有通过远程shell看到这个错误,但我注意到我的本地安装是1.9.23,而日志条目说生产服务器是1.9.25(GoogleAppEngineLauncher说我的本地安装是最新的)
我正在添加一个解决方法来捕获异常并遍历密钥以单独获取它们但我仍然在context.py的第744行看到有关"暂停的生成器获取"的上游警告.
对于至少2个不同的键列表(以及AssertionError之前),警告会出现在列表中第一次获取此实体类型的位置.
我不想以这种方式包装所有get_multi调用.
这是怎么回事?
追溯:
Cannot wrap None
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~thegapnetball/115.386356111937586421/handlers/assess.py", line 50, in get
rs = ndb.get_multi(t.players)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 3905, in get_multi
for future in get_multi_async(keys, **ctx_options)]
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 326, in get_result
self.check_success()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 372, in _help_tasklet_along
value = gen.send(val)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/context.py", line 751, in get
pbs = entity._to_pb(set_key=False).SerializePartialToString()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 3147, in …Run Code Online (Sandbox Code Playgroud) python google-app-engine python-2.7 app-engine-ndb google-cloud-datastore
从今天开始,我一直在使用remote_api(python)来访问GAE上的数据存储区.
我经常这样做remote_api_shell.py -s <mydomain>.
今天我尝试了它失败了,错误是:
oauth2client.client.ApplicationDefaultCredentialsError:应用程序默认凭据不可用.如果在Google Compute Engine中运行,则可以使用它们.否则,必须定义环境变量GOOGLE_APPLICATION_CREDENTIALS,指向定义凭证的文件.有关 详细信息,请参阅 https://developers.google.com/accounts/docs/application-default-credentials.
我不明白为什么它问我.
wole输出就是这个
stefano@~/gc$ remote_api_shell.py -s ....
Traceback (most recent call last):
File "/usr/local/bin/remote_api_shell.py", line 133, in <module>
run_file(__file__, globals())
File "/usr/local/bin/remote_api_shell.py", line 129, in run_file
execfile(_PATHS.script_file(script_name), globals_)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/remote_api_shell.py", line 157, in <module>
main(sys.argv)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/remote_api_shell.py", line 153, in main
appengine_rpc.HttpRpcServer)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/remote_api_shell.py", line 74, in remote_api_shell
secure=secure)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 734, in ConfigureRemoteApiForOAuth
credentials = client.GoogleCredentials.get_application_default()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/oauth2client/oauth2client/client.py", line 1204, in get_application_default
return GoogleCredentials._get_implicit_credentials() …Run Code Online (Sandbox Code Playgroud) 我在Google App Engine中遇到了争用问题,并尝试了解正在发生的事情.
我有一个请求处理程序注释:
@ndb.transactional(xg=True, retries=5)
Run Code Online (Sandbox Code Playgroud)
..在那段代码中,我获取了一些东西,更新了其他一些东西等等.但是有时在请求期间会出现像这样的错误:
16:06:20.930 suspended generator _get_tasklet(context.py:329) raised TransactionFailedError(too much contention on these datastore entities. please try again. entity group key: app: "s~my-appname"
path <
Element {
type: "PlayerGameStates"
name: "hannes2"
}
>
)
16:06:20.930 suspended generator get(context.py:744) raised TransactionFailedError(too much contention on these datastore entities. please try again. entity group key: app: "s~my-appname"
path <
Element {
type: "PlayerGameStates"
name: "hannes2"
}
>
)
16:06:20.930 suspended generator get(context.py:744) raised TransactionFailedError(too much contention on these datastore …Run Code Online (Sandbox Code Playgroud) python google-app-engine contention app-engine-ndb google-cloud-datastore
我正在尝试使用谷歌应用引擎数据库,我需要在2个日期范围内获得员工的总薪水.我需要提供小时的范围,即startDate和endDate,以便我如何在数据存储上执行此操作.我在app引擎数据存储区中使用objectify.
我使用Android Studio创建了Android项目及其后端AppEngine端点对应项.我有一个数据存储区,我正在使用Objectify.系统工作得很好,直到我在查询中添加了一个过滤器(仅显示特定的给定电子邮件).
Query<Report> query = ofy().load().type(Report.class).filter("email", user.getEmail()).order("email").order("-when").limit(limit);
Run Code Online (Sandbox Code Playgroud)
这是POJO数据存储区实体:
@Entity
public class Report {
@Id
Long id;
String who;
@Index
Date when;
String what;
@Index
String email;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试测试时,我从Google API Explorer收到此类错误:
com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
<datastore-index kind=\"AccessReport\" ancestor=\"false\" source=\"manual\">
<property name=\"email\" direction=\"asc\"/>
<property name=\"when\" direction=\"desc\"/>
</datastore-index>
Run Code Online (Sandbox Code Playgroud)
据我所知,我只需要创建一个复合索引,包括特定字段的电子邮件和时间,以及它们的特定排序方向.
但是,我找到的大多数文档都告诉我编辑datastore-indexes.xml.
App Engine预定义实体的每个属性的简单索引.App Engine应用程序可以在名为datastore-indexes.xml的索引配置文件中定义更多自定义索引,该文件在应用程序的/ war/WEB-INF/appengine生成的目录中生成.
不幸的是,这个文件似乎并不存在于我的项目中.
是否有人熟悉使用Android Studio时改变这种情况的方法?
google-app-engine objectify google-cloud-endpoints google-cloud-datastore android-studio
我正在尝试为使用数据存储区的GAE程序编写测试.按照Google的文档,我看到我应该将SDK的路径添加到我的PYTHONPATH中.我这样做使用:
import sys
sys.path.remove('/usr/local/lib/python2.7/dist-packages') # Has a 'google' module, which I want to be sure isn't interfering.
sys.path.insert(1,'/home/olly/google-cloud-sdk/platform/google_appengine')
sys.path.insert(1, '/home/olly/google-cloud-sdk/platform/google_appengine/lib/yaml/lib')
Run Code Online (Sandbox Code Playgroud)
然后在运行文件时:
Traceback (most recent call last):
File "myapp_tests.py", line 20, in <module>
from google.appengine.ext import ndb
ImportError: No module named appengine.ext
Run Code Online (Sandbox Code Playgroud)
我已经安装在上面的位置的SDK,并期待在/home/olly/google-cloud-sdk/platform/google_appengine/我发现google文件夹,里面有一个__init__.py在里面,沿着appengine.基本上,文件夹结构对我来说很好,它们都被正确命名并有__init__.py文件.
在交互式控制台中,运行上面的命令后,我发现我可以运行:
import google
Run Code Online (Sandbox Code Playgroud)
没问题,但是当我尝试的时候
import google.appengine
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named appengine
Run Code Online (Sandbox Code Playgroud)
我的理解是,在__init__.py()目录中包含文件意味着可以像上面那样导入它们.我也做了一个sudo …
python google-app-engine python-2.7 app-engine-ndb google-cloud-datastore
将编译"com.google.firebase:firebase-firestore:11.4.2"添加到我的构建后,我遇到了问题.
一旦我添加它,它还将com.google.common添加到我的dex文件中,这大约是27k额外引用,因此突破了64k dex限制.
有谁知道为什么或我做错了什么?
python ×4
go ×2
objectify ×2
python-2.7 ×2
android ×1
contention ×1
dex ×1
firebase ×1
java ×1