MongoDB InvalidDocument: Cannot encode object

后端 未结 4 1858
粉色の甜心
粉色の甜心 2021-02-12 15:59

I am using scrapy to scrap blogs and then store the data in mongodb. At first i got the InvalidDocument Exception. So obvious to me is that the data is not in the right encoding

4条回答
  •  无人共我
    2021-02-12 16:37

    First, when you do "somestring".encode(...), isn't changing "somestring", but it returns a new encoded string, so you should use something like:

     item['author'] = item['author'].encode('utf-8', 'strict')
    

    and the same for the other fields.

提交回复
热议问题