问题
I am using the Python 2.7 runtime with NDB from the 1.6.2 SDK on Google App Engine.
I get the following error:
BadRequestError: app s~myapphr cannot access app dev~myapphr's data
Originating from this code:
device = model.Key(urlsafe=device_id).get()
I am accessing my app from dev.myapp.appspot.com that is aliased to myapphr. device_id was created on the same dev.myapphr version.
What is going on?
回答1:
the dev server has a default default_partition of 'dev' and on production, HRD apps get a partition of 's'. If you create a urlsafe key on the dev server and store it as a string it will not work on a the production server with a different partition. the way to make keys portable is to save them in a ReferenceProperty with db or KeyProperty on ndb.
回答2:
The prefix you see there ("s~" and "dev~") is called a partition. You can use the --default_partition flag for dev_appserver.py to change the prefix from "dev~" to "s~".
来源:https://stackoverflow.com/questions/9280613/badrequesterror-app-smyapphr-cannot-access-app-devmyapphrs-data-why