无法将数据插入本地Google App Engine数据存储区

时间:2015-10-20 02:21:45

标签: python-2.7 google-app-engine

我正在关注Google's Mobile Shopping Assistant sample中的示例,该示例要求我根据this link导入数据。

我尝试了根据示例的步骤(所有示例代码都是vanilla,我没有改变任何东西,除了修复警告以使用最新的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. 这给了我以下的宣读
  4. 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"但它显示

    3.   

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

           

      以编程方式使用此工具查看和编辑它。

      enter image description here

3 个答案:

答案 0 :(得分:13)

我遇到了同样的问题,但没有使用本地开发人员服务器但使用已部署的版本。在几乎疯了之后,我找到了使用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上观察到同样的问题。

答案 1 :(得分:4)

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

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似乎存在同样的问题(auth检查没有正确更新以使用新的auth方案)。

Python中的解决方法是手动编辑SDK源代码并删除身份验证。我怀疑Java SDK需要类似的黑客攻击。虽然SDK需要从源代码重建,但它并不那么简单。

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

<强>更新

罪魁祸首是com/google/apphosting/utils/remoteapi/RemoteApiServlet.java中的管理员检查,与上面提到的Python SDK中的相同问题一样。遗憾的是,您无法从源代码重建SDK,因为build.xml中的构建目标仅包含“jsr107cache”,其余构建都是从预生成的二进制文件完成的。看起来我们必须等到未来版本中修复此问题,但现在我将更新公共错误。

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

答案 2 :(得分:-1)

最好在谷歌开发者控制台中使用新的用户界面。网址:group_by

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

enter image description here

注意:我还注意到,除非在其中添加了一些数据,否则查询部分中不会显示某种特殊类型[GQL也会返回空数据]。我在索引部分看到了那种特殊的东西。