【问题标题】:fail to insert data into local Google App Engine datastore无法将数据插入本地 Google App Engine 数据存储区
【发布时间】:2016-01-18 12:57:02
【问题描述】:

我正在按照Google's Mobile Shopping Assistant sample 的示例进行操作,该示例要求我根据this link 导入数据。

我根据示例尝试了步骤(所有示例代码都是香草,除了修复警告以使用最新的 Gradle 构建版本之外,我没有更改任何内容)

我认为我遗漏了示例中未说明的基本步骤。有人可以提供一些关于我做错了哪些步骤的见解吗?

以下是我做的步骤

  1. 启动本地 googleAppEngine 应用“后端”
  2. 运行 cmd " appcfg.py upload_data --config_file bulkloader.yaml --url=http ://localhost:8080/remote_api --filename places.csv --kind=Place -e myEmailAddress@gmail.com"。

    这个命令应该在数据存储中插入 2 行(places.csv 包含两个条目)

  3. 这给了我以下读数
10:07 AM Uploading data records.

[INFO    ] Logging to bulkloader-log-20151020.100728

[INFO    ] Throttling transfers:

[INFO    ] Bandwidth: 250000 bytes/second

[INFO    ] HTTP connections: 8/second

[INFO    ] Entities inserted/fetched/modified: 20/second

[INFO    ] Batch Size: 10

Error 302: --- begin server output ---

--- end server output ---
  1. 然后我转到“http://localhost:8080/admin/buildsearchindex”,其中显示“MaintenanceTasks 已完成”。

  2. 接下来我转到“http://localhost:8080/_ah/admin”,但它显示

Datastore 在 Empty 命名空间中没有实体。您需要添加数据

在您可以使用此工具查看和编辑之前以编程方式进行。

【问题讨论】:

  • 你解决了吗?我也有同样的问题
  • @brandall 很遗憾没有,我跳过了这个,而是按照rominirani.com/2014/01/10/… 的例子。
  • 感谢您的回复。我会看一下链接。太令人沮丧了,我看不出我做错了什么...... :(
  • 对 bulkloader 的响应中的“错误 302”似乎表明插入失败。也许看看服务器输出/bulkoader 日志会提供关于发生了什么的线索?
  • @Adam 日志显示与上面相同(以“终端服务器输出”结尾)。我想我要为这个问题加分,因为这个问题太基本了,无法回答!

标签: python-2.7 google-app-engine


【解决方案1】:

我遇到了同样的问题,但不是本地开发人员服务器,而是部署版本。在几乎发疯之后,我找到了一种使用 appcfg 上传数据的解决方法。就我而言,我注意到在尝试以下操作时

输入对我不起作用:

gcloud auth login
appcfg.py upload_data --config_file bulkloader.yaml --url=http://<yourproject>.appspot.com/remote_api --filename places.csv --kind=Place --email=<you@gmail.com>

错误输出:

11:10 AM Uploading data records.
[INFO    ] Logging to bulkloader-log-20160108.111007
[INFO    ] Throttling transfers:
[INFO    ] Bandwidth: 250000 bytes/second
[INFO    ] HTTP connections: 8/second
[INFO    ] Entities inserted/fetched/modified: 20/second
[INFO    ] Batch Size: 10
Error 302: --- begin server output ---

--- end server output ---

正如预期的那样,在第二个命令期间我没有被要求再次验证自己,但显然 appcfg 仍然无法验证我的帐户。我正在使用 Win7、Python 2.7、Python Google App Engine SDK,包括来自 Google Cloud SDK 的 appcfg.py 和 gcloud。

但是,https://cloud.google.com/container-registry/docs/auth 显示您可以使用 gcloud 命令打印出访问令牌,然后手动将其插入对我有用的 appcfg 命令中

输入对我有用:

gcloud auth login
gcloud auth print-access-token

这会打印出您可以与 appcfg 一起使用的访问令牌

appcfg.py upload_data --oauth2_access_token=<oauth2_access_token> --config_file bulkloader.yaml --url=http://<yourproject>.appspot.com/remote_api --filename places.csv --kind=Place --email=<you@gmail.com>

数据上传成功的输出:

10:42 AM Uploading data records.
[INFO    ] Logging to bulkloader-log-20160108.104246
[INFO    ] Throttling transfers:
[INFO    ] Bandwidth: 250000 bytes/second
[INFO    ] HTTP connections: 8/second
[INFO    ] Entities inserted/fetched/modified: 20/second
[INFO    ] Batch Size: 10
[INFO    ] Opening database: bulkloader-progress-20160108.104246.sql3
[INFO    ] Connecting to <yourproject>.appspot.com/remote_api
[INFO    ] Starting import; maximum 10 entities per post
.
[INFO    ] 3 entities total, 0 previously transferred
[INFO    ] 3 entities (4099 bytes) transferred in 1.7 seconds
[INFO    ] All entities successfully transferred

我希望这可以帮助任何试图解决这个问题的人。对我来说,不清楚这个问题的根源是什么,但这是一个适合我的解决方法。

顺便说一句,我在 Mac 上观察到了同样的问题。

【讨论】:

  • 感谢这对我有用!您也可以像这样简化命令以避免复制和粘贴:--oauth2_access_token=`gcloud auth print-access-token`
【解决方案2】:

这是我通过测试发现的。我最初执行了相同的步骤并得到了相同的错误,但输出中值得注意的是条目 INFO client.py:669 access_token is expired:

MobileAssistant-Data> appcfg.py upload_data --config_file bulkloader.yaml --url=http://localhost:8080/remote_api --filename places.csv --kind=Place -e myEmailAddress@gmail.com
05:12 PM Uploading data records.
[INFO    ] Logging to bulkloader-log-20151112.171238
[INFO    ] Throttling transfers:
[INFO    ] Bandwidth: 250000 bytes/second
[INFO    ] HTTP connections: 8/second
[INFO    ] Entities inserted/fetched/modified: 20/second
[INFO    ] Batch Size: 10
2015-11-12 17:12:38,466 INFO client.py:669 access_token is expired. Now: 2015-11-12 22:12:38.466000, token_expiry: 2015-11-06 01:33:21
Error 302: --- begin server output ---

这看起来有点像我在开发服务器的远程 API 处理程序中看到的 issue,它出现在 ClientLogin was deprecated 之后(但在 Python SDK 中)。只是为了测试我编辑了 build.gradle 以使用最新的 SDK 版本(从 1.9.18 到 1.9.28)并再次运行它:

MobileAssistant-Data> appcfg.py upload_data --config_file bulkloader.yaml --url=http://localhost:8080/remote_api --filename places.csv --kind=Place -e myEmailAddress@gmail.com
05:16 PM Uploading data records.
[INFO    ] Logging to bulkloader-log-20151112.171615
[INFO    ] Throttling transfers:
[INFO    ] Bandwidth: 250000 bytes/second
[INFO    ] HTTP connections: 8/second
[INFO    ] Entities inserted/fetched/modified: 20/second
[INFO    ] Batch Size: 10
2015-11-12 17:16:15,177 INFO client.py:669 access_token is expired. Now: 2015-11-12 22:16:15.177000, token_expiry: 2015-11-06 01:33:21
2015-11-12 17:16:15,565 INFO client.py:669 access_token is expired. Now: 2015-11-12 22:16:15.565000, token_expiry: 2015-11-06 01:33:21
2015-11-12 17:16:15,573 INFO client.py:571 Refreshing due to a 401 (attempt 1/2)
2015-11-12 17:16:15,575 INFO client.py:797 Refreshing access_token
2015-11-12 17:16:16,039 INFO client.py:571 Refreshing due to a 401 (attempt 2/2)
2015-11-12 17:16:16,040 INFO client.py:797 Refreshing access_token
... (ad infinitum)

此输出现在完全反映了 Python Remote API 问题。因此,Java Remote API 似乎存在同样的问题(身份验证检查尚未正确更新以使用新的身份验证方案)。

Python 中的解决方法是手动编辑 SDK 源代码并存根验证检查。我怀疑 Java SDK 需要进行类似的破解。这并不像 SDK 需要从源代码重新构建那样简单。

如果我遇到任何其他问题,我会用我的发现更新这个答案。请注意,这对于已部署的应用程序完全可以正常工作 - 只有开发服务器受到影响。

更新:

罪魁祸首是com/google/apphosting/utils/remoteapi/RemoteApiServlet.java 中的管理员检查,与上述 Python SDK 中的相同问题相同。不幸的是,您不能轻易地从源代码重建 SDK,因为 build.xml 中的构建目标仅包含“jsr107cache”,而其余的构建是从预生成的二进制文件完成的。看起来我们只能等到这个问题在未来的版本中得到修复,但现在我将更新公共错误。

目前我建议坚持使用文档并仅使用已部署的应用版本进行 remote_api 上传。

【讨论】:

【解决方案3】:

更好地使用谷歌开发者控制台中的新 UI。网址:https://console.developers.google.com/project/&lt;YOUR_PROJECT_ID&gt;/datastore

您可以查看针对您的种类的查询或索引子部分[您也可以使用 GQL] 和索引。

注意:我还注意到查询部分中不会出现特定类型,除非在其中添加了一些数据[GQL 也返回空数据]。不过,我在索引部分看到了这种特殊类型。

【讨论】:

  • 是否有 localhost 获取新 UI 的链接?
  • 我不确定它在 localhost 上的表现如何。
  • 新 UI 仅适用于已部署的应用程序。开发服务器只有一个基本 UI,Angel 已经在使用它。
  • 这个 UI 不允许我们上传 csv 数据文件,虽然……就像我们过去的“upload_data”系统一样?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-31
  • 2011-02-16
  • 2013-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多