Try below code line instead of last two lines. Hope it helps:
line=line.decode('utf-8','ignore').encode("utf-8")
More Related Contents:
- “Large data” workflows using pandas [closed]
- UnicodeEncodeError: ‘charmap’ codec can’t encode – character maps to , print function [duplicate]
- Python UnicodeDecodeError – Am I misunderstanding encode?
- Python Unicode Encode Error
- TypeError: ObjectId(”) is not JSON serializable
- Python & MySql: Unicode and Encoding
- mongodb: insert if not exists
- How to import data from mongodb to pandas?
- Query Mongodb on month, day, year… of a datetime
- search by ObjectId in mongodb with pymongo
- Insert a Pandas Dataframe into mongodb using PyMongo
- How to sort mongodb with pymongo
- Why is PyMongo 3 giving ServerSelectionTimeoutError?
- Authenticate After Picking the Database
- Fast or Bulk Upsert in pymongo
- How to make a query date in mongodb using pymongo?
- Append item to MongoDB document array in PyMongo without re-insertion
- Append item to MongoDB document array in PyMongo without re-insertion
- How to Ignore Duplicate Key Errors Safely Using insert_many
- Getting Spark, Python, and MongoDB to work together
- How to convert a pymongo.cursor.Cursor into a dict?
- Using .sort with PyMongo
- mongodb cursor id not valid error
- How to continue insertion after duplicate key error using PyMongo
- Convert int to ASCII and back in Python
- How to run raw mongodb commands from pymongo
- ImportError: No module named objectid
- How to extract the substring between two markers?
- Python regex match OR operator
- How to implement server push in Flask framework?