I had written a source code to derive performance of stocks. It is running in an instance efficiently but showing "UnicodeDecodeError" while running in my local. I reffered this python: UnicodeDecodeError: 'utf8' codec can't decode byte 0xc0 in position 0: invalid start byte, but still I am confusing about how it works in an instance without error and how can I solve it? I would highly appreciate if you coud answer me with a solution since I am new to this encode and decode stuff in python.
Following is the function in which the error occurs
def CollectFromDate(eb_grade, year, month):
global monthly_days, end_date
start_date = datetime.strptime('%s%s01' % (year, '0%s' % month if month<10 else month) , '%Y%m%d')
No_days = monthrange(year, month)[1]
end_date = datetime.strptime('%s%s%s' % (year, '0%s' % month if month<10 else month, No_days) , '%Y%m%d')
monthly_days = [(start_date+timedelta(i)).strftime('%Y%m%d') for i in range(No_days)]
MemBackup = db.memcache_backup.find({'_id' : {'$in': monthly_days}})
ScripFrom = {}
for DATA in MemBackup:
date = DATA.pop('_id')
for scrip, val in DATA.items():
valuation = val['pro_valuation_average']['result']
if valuation in ['Strong Upside', 'Upside'] and val['eb_score'][1] in eb_grade and scrip not in ScripFrom:
ScripFrom[scrip] = [{'from': date, 'from_val': valuation}]
return ScripFrom
and following is the Error
Traceback (most recent call last):
File "/Users/faizalmohammed/Mvc-EB/lib/excellent_companies.py", line 201, in <module>
pprint (ProcessPerformanceData(eb_grade, year, month))
File "/Users/faizalmohammed/Mvc-EB/lib/excellent_companies.py", line 79, in ProcessPerformanceData
ScripPerform = CollectFromDate(eb_grade, year, month)
File "/Users/faizalmohammed/Mvc-EB/lib/excellent_companies.py", line 176, in CollectFromDate
for DATA in MemBackup:
File "/Library/Python/2.7/site-packages/pymongo/cursor.py", line 814, in next
if len(self.__data) or self._refresh():
File "/Library/Python/2.7/site-packages/pymongo/cursor.py", line 776, in _refresh
limit, self.__id))
File "/Library/Python/2.7/site-packages/pymongo/cursor.py", line 720, in __send_message
self.__uuid_subtype)
File "/Library/Python/2.7/site-packages/pymongo/helpers.py", line 112, in _unpack_response
as_class, tz_aware, uuid_subtype)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xdf in position 2: invalid continuation byte