1

エラーが発生しました

BadValueError: Virtual property is read-only

このエラーに関するドキュメントは見つかりませんでした。どういう意味ですか?コードの関連部分は次のとおりです。最近の SDK の更新までは機能していました。

date = dt.datetime.strptime(self.json['birthday'],"%Y-%m-%d").date()
if self.json.has_key('avatar'):
    img = base64.b64decode(self.json['avatar'])
else:
    img = None
    log.info('No avatar')
user = db.User(
    name=self.json['name'], 
    password=self.json['password'], 
    full_name=self.json['full_name'],
    email = self.json['email'],
    birthday = date,
    avatar = img)
user.put()

サーバーログ

  File "/api/tornado/web.py", line 1064, in _execute
    getattr(self, self.request.method.lower())(*args, **kwargs)
  File "user.py", line 31, in post
    avatar = img)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 970, in __init__
    prop.__set__(self, value)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 615, in __set__
    setattr(model_instance, self._attr_name(), value)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 3874, in __set__
    raise BadValueError('Virtual property is read-only')
BadValueError: Virtual property is read-only
INFO     2013-06-08 07:44:37,776 server.py:585] default: "POST /api/user/create HTTP/1.1" 500 93

DB モデル

class User(db.Model):
    name = db.StringProperty(required=True)
    password = db.StringProperty(required=True)
    email = db.StringProperty(required=True)
    full_name = db.StringProperty()    
    birthday = db.DateProperty()
    avatar = db.BlobProperty()

外すと

avatar = img

次に、上の行のエラー。

4

2 に答える 2

0

見逃したのは、ドキュメントの次のとおりです。

Blob is for binary data, such as images. **It takes a str value**, but this value
is stored as a byte string and is not encoded as text. Use a Text instance for 
large text data.

Blob をアップロードするには、次のチュートリアルを実行する必要があります: https://developers.google.com/appengine/docs/python/blobstore

そしてあなたのモデルでは:

 avatar = db.BlobProperty() <-- you store the key to the uploaded avatar.

したがって、モデルでは、ブロブ自体ではなく、ブロブ参照へのキーを保存するだけです。それが明確であることを願っています。

次のチュートリアルもご覧ください。これは私を大いに助けてくれました:

于 2013-06-08T11:59:20.340 に答える