TypeError:write() argument must be str, not bytes
程序员文章站
2022-03-11 08:29:28
...
class ItcastPipeline(object):
def init(self):
self.f = open(“itcast_pipelines.json”,“w”)
def process_item(self, item, spider):
content = json.dumps(dict(item), ensure_ascii=False) + ", \n"
self.f.write(content.encode("utf-8"))
return item
#返回给引擎
def close_spider(self,spider):
self.f.close()
将文件打开方式改为wb二进制方式打开,解决问题
推荐阅读
-
解决报错:TypeError: argument should be integer or bytes-like object, not ‘str‘
-
TypeError: join() argument must be str or bytes, not ‘PosixPath‘
-
编译安卓源码提示:TypeError: argument should be integer or bytes-like object, not ‘str‘
-
TypeError: the JSON object must be str, bytes or bytearray, not NoneType
-
TypeError: write() argument must be str, not bytes报错
-
Python报错:TypeError: the JSON object must be str, bytes or bytearray, not ‘dict‘
-
Module build failed: TypeError [ERR_INVALID_ARG_TYPE]: The “from“ argument must be of type string
-
Python网络编程报错TypeError: a bytes-like object is required, not 'str' 的解决办法
-
TypeError: argument 1 must be 2-item sequence, not int
-
用Matplotlib给子图添加图例时出错ax.legend() TypeError zip argument #2 must support iteration