現在,以下代碼行可在本地服務器上正常工作,但在部署時,它會提升SystemError exception
。我一直在試圖找出異常來自哪裏,但一切看起來都很好,或者有些事情可能不正確。如果有人能夠伸出援手,會很高興。部署時出現SystemError異常
這裏是我的代碼
def watermark(img, mark, position=(0, 0), opacity=1, scale=1.0, tile=False, greyscale=False, rotation=0, return_name=False, **kwargs):
"""
Adds a watermark to an image.
"""
if opacity < 1:
mark = reduce_opacity(mark, opacity)
if type(scale) != tuple:
scale = determine_scale(scale, img, mark)
mark = mark.resize(scale, Image.ANTIALIAS)
if greyscale and mark.mode != 'LA':
mark = mark.convert('LA')
rotation = determine_rotation(rotation, mark)
if rotation != 0:
# give some leeway for rotation overlapping
new_w = mark.size[0] * 1.5
new_h = mark.size[1] * 1.5
new_mark = Image.new('RGBA', (new_w, new_h), (0,0,0,0))
# center the watermark in the newly resized image
new_l = (new_w - mark.size[0])/2
new_t = (new_h - mark.size[1])/2
new_mark.paste(mark, (new_l, new_t))
mark = new_mark.rotate(rotation)
position = determine_position(position, img, mark)
print position
if img.mode != 'RGBA':
img = img.convert('RGBA')
# make sure we have a tuple for a position now
assert isinstance(position, tuple), 'Invalid position "%s"!' % position
# create a transparent layer the size of the image and draw the
# watermark in that layer.
layer = Image.new('RGBA', img.size, (0,0,0,0))
if tile:
first_y = position[1] % mark.size[1] - mark.size[1]
first_x = position[0] % mark.size[0] - mark.size[0]
for y in range(first_y, img.size[1], mark.size[1]):
for x in range(first_x, img.size[0], mark.size[0]):
layer.paste(mark, (x, y))
else:
layer.paste(mark, (0, 0))# Traceback points this line, but it doesn't look wrong to me
# composite the watermark with the layer
return Image.composite(layer, img, layer)
堆棧跟蹤
SystemError at/
new style getargs format but argument is not a tuple
Request Method: POST Request URL: example.com/ Django Version:
1.7.1 Exception Type: SystemError Exception Value:
new style getargs format but argument is not a tuple
Exception Location:
/path/to/app/lib/python2.7/PIL/Image.py in paste, line 1334
Python Executable: /usr/bin/python Python Version: 2.7.5
/path/to/app/folder/watermark.py in watermark
214. layer.paste(mark, (0, 0))
/path/to/app/lib/python2.7/PIL/Image.py in paste
1334. self.im.paste(im, box)
也許你在開發中安裝了Pillow,但是沒有在生產中安裝? –
這可能是由具有不同模式的'mark'和'new_mark'造成的。在粘貼之前,您可以嘗試確保兩者都是RGBA。這個異常消息確實沒有幫助,所以我在這裏猜測。 –
謝謝,我試過了,但是錯誤仍然存在 – phourxx