当我尝试通过Web表单将图像(blob)和其他一些数据发布到数据存储区时,我在Google App Engine上收到以下错误。代码可以在我的本地计算机上运行,但不能在我上传到GAE环境时使用。 :
<type 'str'> has type <type 'str'>, but expected one of: int, long, bool
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
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~mygrajj/1.371507856337629790/main.py", line 123, in post
car.put()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 3232, in _put
return self._put_async(**ctx_options).get_result()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 325, in get_result
self.check_success()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 368, in _help_tasklet_along
value = gen.throw(exc.__class__, exc, tb)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/context.py", line 748, in put
key = yield self._put_batcher.add(entity, options)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 371, 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 280, in _put_tasklet
keys = yield self._conn.async_put(options, datastore_entities)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/datastore/datastore_rpc.py", line 1574, in async_put
pbs = [self.__adapter.entity_to_pb(entity) for entity in entities]
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 570, in entity_to_pb
pb = ent._to_pb()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 2945, in _to_pb
prop._serialize(self, pb, projection=self._projection)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 1297, in _serialize
p.set_multiple(self._repeated or parent_repeated)
File "cpp_message.pyx", line 124, in cpp_message.SetScalarAccessors.Setter (third_party/apphosting/python/protobuf/proto1/cpp_message.cc:2229)
TypeError: <type 'str'> has type <type 'str'>, but expected one of: int, long, bool
尝试执行以下代码时:
class AddCar(blobstore_handlers.BlobstoreUploadHandler, webapp2.RequestHandler):
def post(self):
car = Car()
if self.get_uploads('file'):
upload_files = self.get_uploads('file') # 'file' is file upload field in the form
blob_info = upload_files[0]
car.CarBlobKey = blob_info.key()
car.CarImageServingURL.append(images.get_serving_url(blob_info.key()))
car.CarYear = self.request.get('modelyear0')+self.request.get('modelyear1')+self.request.get('modelyear2')
car.CarMake = self.request.get('makeField')
car.CarModel = self.request.get('modelField')
car.CarPosterGrajjStatus = self.request.get('which_grajj')
if users.get_current_user():
car.CarPoster = users.get_current_user()
car.put()
#grajj_query = Car.query()
#cars = grajj_query.fetch(100)
self.redirect('/mygrajj.html')
这是我的模特:
class Car(ndb.Model):
# Car class contains data on a prototype car
CarYear = ndb.StringProperty()
CarMake = ndb.StringProperty()
CarModel = ndb.StringProperty()
CarPoster = ndb.UserProperty()
CarPosted = ndb.DateTimeProperty(auto_now_add="true")
CarPosterGrajjStatus = ndb.StringProperty()
CarBlobKey = ndb.BlobKeyProperty(indexed="false")
CarImageServingURL = ndb.StringProperty(indexed="false", repeated="true")
代码可以在我的本地计算机上运行,但不能在部署时使用
答案 0 :(得分:0)
如何删除blob并隔离问题所在。
答案 1 :(得分:0)
我认为此行会引用NoneType
,因为CarImageServingURL
没有默认值。
car.CarImageServingURL.append(images.get_serving_url(blob_info.key()))
您可以将其重写为
car.CarImageServingURL = images.get_serving_url(blob_info.key())
或者尝试将定义更改为默认值:
CarImageServingURL = ndb.StringProperty(indexed="false", repeated="true", default="")
答案 2 :(得分:0)
您需要将所有参数更改为布尔值
class Car(ndb.Model):
# Car class contains data on a prototype car
CarYear = ndb.StringProperty()
CarMake = ndb.StringProperty()
CarModel = ndb.StringProperty()
CarPoster = ndb.UserProperty()
CarPosted = ndb.DateTimeProperty(auto_now_add="true")
CarPosterGrajjStatus = ndb.StringProperty()
CarBlobKey = ndb.BlobKeyProperty(indexed="false")
CarImageServingURL = ndb.StringProperty(indexed="false", repeated="true")
auto_now_add=True
indexed=False
repeated=True
省略“”