UnicodeDecodeError: 'ascii'编解码器无法解码第10个位置的0x87字节:该序号不在128范围内。

5
我正在使用images2gif并遇到了这个错误。有什么想法吗?
UnicodeDecodeError:'ascii'编解码器无法解码第10个位置的0x87字节:序数不在范围内(128)
测试文件:
from PIL import Image
from images2gif import writeGif

FRAMES = 2
FRAME_DELAY = 0.75
WIDTH, HEIGHT = 600, 600

frames = []
img1 = Image.open('1.jpg')
img2 = Image.open('2.jpg')
frames.append(img1)
frames.append(img2)

writeGif("test.gif", frames, duration=FRAME_DELAY, dither=0)

回溯:

Traceback (most recent call last):
  File "gif.py", line 15, in <module>
    writeGif("topmovie.gif", frames, duration=FRAME_DELAY, dither=0)
  File "/Users/Craig/Documents/github/RTB/images2gif.py", line 575, in writeGif
    gifWriter.writeGifToFile(fp, images, duration, loops, xy, dispose)
  File "/Users/Craig/Documents/github/RTB/images2gif.py", line 435, in writeGifToFile
    fp.write(header.encode('utf-8'))

图片转GIF的第435行代码:fp.write(header.encode('utf-8'))

更新的追踪信息:

Traceback (most recent call last):
  File "gif.py", line 16, in <module>
    writeGif("test.gif", frames, duration=FRAME_DELAY, dither=0)
  File "/Users/Craig/Documents/github/RTB/images2gif.py", line 579, in writeGif
    gifWriter.writeGifToFile(fp, images, duration, loops, xy, dispose)
  File "/Users/Craig/Documents/github/RTB/images2gif.py", line 440, in writeGifToFile
    fp.write(globalPalette)
TypeError: must be string or buffer, not None

1
你使用的是哪个Python版本? - aIKid
你正在使用哪个版本的images2gif?我在最新版本中没有看到那一行。 - PasteBT
1
请仅返回翻译文本:这个版本没有编码问题,对我来说似乎更合理 https://github.com/luopio/bag-of-tricks/blob/master/python/images2gif.py。无法猜测为什么可以对字符串进行编码;image2gif的代码看起来不太适用于Py3,所以我猜它是为Py2编写的。 - alko
4
建议使用Pillow代替几乎不再更新的PIL库:https://pypi.python.org/pypi/Pillow/ - Laurent LAPORTE
@CraigCannon 看起来pypi上最新版本(1.0.1)比上面提供的版本(由@alko提供)更新,而且链接的bitbucket仓库甚至更加新(10/2013),这可能意味着其中有一些错误修复/功能提交。请尝试升级并再次运行您的代码。此外,您可以将问题与源图像一起提交到bitbucket仓库。 - tutuDajuju
显示剩余2条评论
1个回答

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接