python exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xa7 in -


i using scrapy python , have code in python item pipline

def process_item(self, item, spider):         import pdb; pdb.set_trace()         id = str(uuid.uuid5(uuid.namespace_dns, item['link'])) 

i got error :

        traceback (most recent call last):           file "c:\python27\lib\site-packages\scrapy-0.20.2-py2.7.egg\scrapy\mid dleware.py", line 62, in _process_chain             return process_chain(self.methods[methodname], obj, *args)           file "c:\python27\lib\site-packages\scrapy-0.20.2-py2.7.egg\scrapy\uti ls\defer.py", line 65, in process_chain             d.callback(input)           file "c:\python27\lib\site-packages\twisted\internet\defer.py", line 3 82, in callback             self._startruncallbacks(result)           file "c:\python27\lib\site-packages\twisted\internet\defer.py", line 4 90, in _startruncallbacks             self._runcallbacks()         --- <exception caught here> ---           file "c:\python27\lib\site-packages\twisted\internet\defer.py", line 5 77, in _runcallbacks             current.result = callback(current.result, *args, **kw)           file "general_spider_code_version_2\pipelines.py", line 7, in process_ item             id = str(uuid.uuid5(uuid.namespace_dns, item['link']))           file "c:\python27\lib\uuid.py", line 549, in uuid5             hash = sha1(namespace.bytes + name).digest()         exceptions.unicodedecodeerror: 'ascii' codec can't decode byte 0xa7 in p osition 1: ordinal not in range(128) 

i tried debug item['link']

and result

-> id = str(uuid.uuid5(uuid.namespace_dns, item['link'])) (pdb) item['link'] u'http://dubai.dubizzle.com/property-for-rent/residential/apartmentflat/2014/4/6 /palm-jumeirah-abu-keibal-3-br-maid-partial-2/?back=zhviywkuzhviaxp6bguuy29tl3by b3blcnr5lwzvci1yzw50l3jlc2lkzw50awfsl2fwyxj0bwvudgzsyxqv&pos=1' (pdb) 

as see item['link'] unicode

edit1

when change item['link'] other attribute item['date'] code works perfectly

encode unicode string byte string .encode('utf-8') , should work:

str(uuid.uuid5(uuid.namespace_dns, item['link'].encode('utf-8'))) 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -