on web2py 2.9.5
obj[key]  I pass a unicode

Solution
now pass
obj[key] a string

and on gluon/serializers.py line 167 I changed (encode for decode)

return str(obj[key]).encode('utf-8', 'replace') if key in obj else default
for
return str(obj[key]).decode('utf-8', 'replace') if key in obj else default

now work fine for me.

I think the problem is in encode fail when is a string (with special 
characters)



El martes, 18 de noviembre de 2014 08:57:39 UTC+1, dam...@gmail.com 
escribió:
>
> Hi:
> This patch broke my rss.
> When update web2py 2.9.5 to 2.9.11 the RSS produces an encoding error.
>
>
> Ticket ID 
>>
>> 192.168.0.109.2014-11-18.08-43-24.a4e11dac-b0ab-49b8-83b7-105ea1ba5ad2
>> <type 'exceptions.UnicodeEncodeError'> 'ascii' codec can't encode 
>> character u'\xf3' in position 23: ordinal not in range(128) Version  
>> web2py™ Version 2.9.11-stable+timestamp.2014.09.15.23.35.11  Python Python 
>> 2.7.3: /usr/bin/python (prefix: /usr)  Traceback 
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>> 10.
>> 11.
>>
>> Traceback (most recent call last):
>>   File "/home/www-data/web2py/gluon/restricted.py", line 224, in restricted
>>     exec ccode in environment
>>   File 
>> "/home/www-data/web2py/applications/mp/modules/plugins/feed/feed.rss", line 
>> 12, in <module>
>>     from gluon.serializers import rss
>>   File "/home/www-data/web2py/gluon/serializers.py", line 172, in rss
>>     description=safestr(feed,'description'),
>>   File "/home/www-data/web2py/gluon/serializers.py", line 167, in safestr
>>     return str(obj[key]).encode('utf-8', 'replace') if key in obj else 
>> default
>> UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 
>> 23: ordinal not in range(128)
>>
>> Error snapshot [image: help] 
>> <https://192.168.0.5/admin/default/ticket/mp/192.168.0.109.2014-11-18.08-43-24.a4e11dac-b0ab-49b8-83b7-105ea1ba5ad2#>
>>  
>>
>> <type 'exceptions.UnicodeEncodeError'>('ascii' codec can't encode 
>> character u'\xf3' in position 23: ordinal not in range(128)) 
>>
>
> when restore web2py/gluon/serializers.py to version 2.9.5 work fine
>
> My python version is 2.7.3
> will relate to this? 
> https://groups.google.com/forum/#!topic/web2py/8ZwVMKS69Sg
>
> My feed.rss page is:
> dd=dict(title="my feed",
>             link=u"feed.example.com",
>             description="carácter acentuado".decode('utf-8'),
>             entries=[
>               dict(title="my feed",
>               link=u"http://feed.example.com";,
>               description="my first feed")
>             ])
> from gluon.serializers import rss   
> response.write(rss(dd), escape=False)
> response.headers['Content-Type']='application/rss+xml'
>
>
> El miércoles, 10 de septiembre de 2014 15:27:07 UTC+2, Massimo Di Pierro 
> escribió:
>>
>> Sorry for the trouble here:
>>
>> I pushed this to trunk:
>> def rss(feed):
>>     if not 'entries' in feed and 'items' in feed:
>>         feed['entries'] = feed['items']
>>     def safestr(obj, key, default=''):
>>         return str(obj[key]).encode('utf-8', 'replace') if key in obj 
>> else default
>>
>>     now = datetime.datetime.now()
>>     rss = rss2.RSS2(title=safestr(feed,'title'),
>>                     link=safestr(feed,'link'),
>>                     description=safestr(feed,'description'),
>>                     lastBuildDate=feed.get('created_on', now),
>>                     items=[rss2.RSSItem(
>>                            title=safestr(entry,'title','(notitle)'),
>>                            link=safestr(entry,'link'),
>>                            description=safestr(entry,'description'),
>>                            pubDate=entry.get('created_on', now)
>>                            ) for entry in feed.get('entries', [])])
>>     return rss.to_xml(encoding='utf-8')
>>
>> please let me know if this fixes it. If not, please send me more details 
>> about the feed you are trying to read.
>>
>>  
>>
> On Tuesday, 9 September 2014 00:45:25 UTC-5, Капылов Данил wrote:
>>>
>>> Does not work. :-)
>>>
>>> Error ticket for "welcome"Ticket ID
>>>
>>> 127.0.0.1.2014-09-09.11-33-31.6f78e65a-5d28-410e-9111-55ded191b520
>>> <type 'exceptions.AttributeError'> 'NoneType' object has no attribute 
>>> 'encode'Версияweb2py™Version 2.9.9-stable+timestamp.2014.09.08.13.16.54
>>> PythonPython 2.7.6: C:\Python27\python.exe (prefix: C:\Python27)
>>> Traceback
>>>
>>> 1.
>>> 2.
>>> 3.
>>> 4.
>>> 5.
>>> 6.
>>> 7.
>>> 8.
>>> 9.
>>>
>>> Traceback (most recent call last):
>>>   File 
>>> "C:\Users\�����\Documents\MEGAsync\Web2pyProject\Ad\web2py\gluon\restricted.py",
>>>  line 221, in restricted
>>>     exec ccode in environment
>>>   File 
>>> "C:\Users\�����\Documents\MEGAsync\Web2pyProject\Ad\web2py\applications\welcome\views\generic.rss",
>>>  line 10, in <module>
>>>     from gluon.serializers import rss}}{{=XML(rss(response._vars))}}
>>>   File 
>>> "C:\Users\�����\Documents\MEGAsync\Web2pyProject\Ad\web2py\gluon\serializers.py",
>>>  line 168, in rss
>>>     link=str((feed.get('link') or '').encode('utf-8', 'replace')),
>>> AttributeError: 'NoneType' object has no attribute 'encode'
>>>
>>> Error snapshot [image: help] 
>>> <http://127.0.0.1:8000/admin/default/ticket/welcome/127.0.0.1.2014-09-09.11-33-31.6f78e65a-5d28-410e-9111-55ded191b520#>
>>>
>>> <type 'exceptions.AttributeError'>('NoneType' object has no attribute 
>>> 'encode')
>>>
>>> inspect attributes
>>> Frames
>>>    
>>>    - 
>>>    
>>>    *File 
>>>    
>>> C:\Users\�����\Documents\MEGAsync\Web2pyProject\Ad\web2py\gluon\restricted.py
>>>  
>>>    in restricted at line 221* код аргументы переменные
>>>    - 
>>>    
>>>    *File 
>>>    
>>> C:\Users\�����\Documents\MEGAsync\Web2pyProject\Ad\web2py\applications\welcome\views\generic.rss
>>>  
>>>    in <module> at line 10* код аргументы переменные
>>>    - 
>>>    
>>>    *File 
>>>    
>>> C:\Users\�����\Documents\MEGAsync\Web2pyProject\Ad\web2py\gluon\serializers.py
>>>  
>>>    in rss at line 168* код аргументы переменные
>>>    Function argument list
>>>    
>>>    (feed={'message': <lazyT 'Hello World'>})
>>>    Code listing
>>>    
>>>    163.
>>>    164.
>>>    165.
>>>    166.
>>>    167.
>>>    168.
>>>    
>>>    169.
>>>    170.
>>>    171.<span style="color:
>>>    
>>>    
>>> ...
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to