且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python 错误类型错误:必须是字符串或缓冲区,而不是实例

更新时间:2022-11-12 15:46:41

如果没有看到堆栈跟踪很难确定,但我怀疑这一行:

It's hard to say for sure without seeing the stack trace, but I suspect this line:

imageFile.write(urllib.urlopen(filename)).read()

应该是:

imageFile.write(urllib.urlopen(filename).read())

顺便说一句,您不需要 imageFile.close() 行,因为 with 语句会自动为您关闭文件.

Incidentally, you don't need the imageFile.close() line, because the with statement closes the file for you automatically.