當我嘗試從URL獲取圖像並將其響應中的字符串轉換爲App Engine中的Image
時,我收到上述消息的錯誤。PIL ValueError:沒有足夠的圖像數據?
from google.appengine.api import urlfetch
def fetch_img(url):
try:
result = urlfetch.fetch(url=url)
if result.status_code == 200:
return result.content
except Exception, e:
logging.error(e)
url = "http://maps.googleapis.com/maps/api/staticmap?center=Narita+International+Airport,Narita,Chiba+Prefecture,+Japan&zoom=18&size=512x512&maptype=roadmap&markers=color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.&markers=color:red|color:red|label:C|40.718217,-73.998284&sensor=false"
img = fetch_img(url)
# As the URL above tells, its size is 512x512
img = Image.fromstring('RGBA', (512, 512), img)
根據PIL,size選項被假設爲一個像素元組。這我指定。有誰能指出我的誤解嗎?
當問一個問題,請包括整個堆棧跟蹤,而不是意譯錯誤我們。 –