こんにちは、すべての一般的なアイデアは、銀河のようなマップを作成することです。生成された画像を表示しようとすると問題が発生します。Python Image ライブラリを使用してイメージを作成し、データストアに保存しました。
イメージを読み込もうとすると、ログ コンソールにエラーが表示されず、ブラウザにイメージが表示されません。画像リンク (データストア キーを含む) をコピーして貼り付けると、黒い画面と次のメッセージが表示されます。
画像「view-source:/localhost:8080/img?img_id=ag5kZXZ-c3BhY2VzaW0xMnINCxIHTWFpbk1hcBgeDA」はエラーがあるため表示できません。
Firefox エラー コンソール:
エラー: 画像が破損しているか切り捨てられています: /localhost:8080/img?img_id=ag5kZXZ-c3BhY2VzaW0xMnINCxIHTWFpbk1hcBgeDA
import cgi
import datetime
import urllib
import webapp2
import jinja2
import os
import math
import sys
from google.appengine.ext import db
from google.appengine.api import users
from PIL import Image
#SNIP
#class to define the map entity
class MainMap(db.Model):
defaultmap = db.BlobProperty(default=None)
#SNIP
class Generator(webapp2.RequestHandler):
def post(self):
#SNIP
test = Image.new("RGBA",(100, 100))
dMap=MainMap()
dMap.defaultmap = db.Blob(str(test))
dMap.put()
#SNIP
result = db.GqlQuery("SELECT * FROM MainMap LIMIT 1").fetch(1)
if result:
print"item found<br>" #debug info
if result[0].defaultmap:
print"defaultmap found<br>" #debug info
string = "<div><img src='/img?img_id=" + str(result[0].key()) + "' width='100' height='100'></img>"
print string
else:
print"nothing found<br>"
else:
self.redirect('/?=error')
self.redirect('/')
class Image_load(webapp2.RequestHandler):
def get(self):
self.response.out.write("started Image load")
defaultmap = db.get(self.request.get("img_id"))
if defaultmap.defaultmap:
try:
self.response.headers['Content-Type'] = "image/png"
self.response.out.write(defaultmap.defaultmap)
self.response.out.write("Image found")
except:
print "Unexpected error:", sys.exc_info()[0]
else:
self.response.out.write("No image")
#SNIP
app = webapp2.WSGIApplication([('/', MainPage),
('/generator', Generator),
('/img', Image_load)],
debug=True)
ブラウザに「item found」と「defaultmap found」の文字列と壊れた画像リンクが表示される 例外処理でエラーが捕捉されない
助けてくれてありがとう よろしく バート