Fixed issue 1422 introduced a bug in generic rss views?

223 views
Skip to first unread message

Loïc

unread,
May 29, 2013, 9:06:07 AM5/29/13
to web...@googlegroups.com
Hi All,

It seems that the fix for issue 1422 introduced a bug on generic rss views.
History :
https://github.com/web2py/web2py/commit/ea34d1b3a02223e3032d91ad9269d70dcfd5f0b6#gluon/serializers.py

First error :
On gluon/serializers.py, line 166 if feed.get() returns None we can't call .encode()  The following error is raised :

Error ticket for "udsp25"

Ticket ID

127.0.0.1.2013-05-29.14-41-05.3b4f5f26-486e-4094-b32e-838d2bedd4e5

<type 'exceptions.AttributeError'> 'NoneType' object has no attribute 'encode'

Version

web2py™ Version 2.4.7-stable+timestamp.2013.05.24.17.48.47
Python Python 2.7.3: 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\MCR\Google Drive\loic\web2py\web2py\gluon\restricted.py", line 212, in restricted
exec ccode in environment
File "C:\Users\MCR\Google Drive\loic\web2py\web2py\applications\udsp25\views\generic.rss", line 10, in <module>
from gluon.serializers import rss}}{{=XML(rss(response._vars))}}
File "C:\Users\MCR\Google Drive\loic\web2py\web2py\gluon\serializers.py", line 166, in rss
link=str(feed.get('link', None).encode('utf-8', 'replace')),
AttributeError: 'NoneType' object has no attribute 'encode'


Second error :
On gluon/serializers.py, line 174 feed.get('entries', []) seems to have an encoding problem...

Error ticket for "dommartin25"

Ticket ID

127.0.0.1.2013-05-29.14-49-25.63d546c2-feb6-43e4-b6f2-0cb4fc6bb022

<type 'exceptions.UnicodeDecodeError'> 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)

Version

web2py™ Version 2.4.7-stable+timestamp.2013.05.24.17.48.47
Python Python 2.7.3: 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\MCR\Google Drive\loic\web2py\web2py\gluon\restricted.py", line 212, in restricted
exec ccode in environment
File "C:\Users\MCR\Google Drive\loic\web2py\web2py\applications\dommartin25\views\generic.rss", line 10, in <module>
from gluon.serializers import rss}}{{=XML(rss(response._vars))}}
File "C:\Users\MCR\Google Drive\loic\web2py\web2py\gluon\serializers.py", line 174, in rss
) for entry in feed.get('entries', [])])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)

Do you know how to fix it?
Thank you!

Sebastian Ortiz Vasquez

unread,
May 30, 2013, 3:57:31 PM5/30/13
to web...@googlegroups.com
Hi,

Yes, in order to get this working, you should also update your cpython distribution, check the bug here

http://bugs.python.org/issue17606

Niphlod

unread,
May 30, 2013, 4:10:24 PM5/30/13
to web...@googlegroups.com
uhm. so it works only in 2.7 ?

Sebastian Ortiz Vásquez

unread,
May 30, 2013, 4:14:45 PM5/30/13
to web...@googlegroups.com
Maybe, you can try to apply the patch to your distribution of cpython, sax_utils.py always can be found.


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/8ZwVMKS69Sg/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Sebastián Ortiz Vásquez.
2013

Niphlod

unread,
May 30, 2013, 5:03:57 PM5/30/13
to web...@googlegroups.com
my point was that web2py needs to run on 2.5 AND 2.6 AND 2.7 .
If code relies on the standard library, it needs to be adapted...
a patch is issued to correct a misbehaviour...
if instead it broke every python "old" version with an incompatible sax library it needs to be either adapted or reverted.

Sebastian Ortiz Vásquez

unread,
May 30, 2013, 5:07:24 PM5/30/13
to web...@googlegroups.com
I aggree with you, perhaps it need to be adapted again.

Loïc ESPERN

unread,
May 30, 2013, 5:08:48 PM5/30/13
to web...@googlegroups.com

I'm currently using python 2.7.3
Should I update to the latest 2.7.5 to get this work ?

--

Sebastian Ortiz Vásquez

unread,
May 30, 2013, 5:09:53 PM5/30/13
to web...@googlegroups.com
Is not mandatory, is enough appling the patch described above to the sax_parser.

Loïc

unread,
May 31, 2013, 6:30:34 AM5/31/13
to web...@googlegroups.com
Sorry but I installed latest python version on my laptop (python 2.7.5 on Win7 x64) and it still doesn't work : 

<type 'exceptions.UnicodeDecodeError'> 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)

Version

web2py™Version 2.4.7-stable+timestamp.2013.05.24.17.48.47
PythonPython 2.7.5: C:\Python27\python.exe (prefix: C:\Python27)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
Traceback (most recent call last
):
File "D:\Google Drive\loic\web2py\web2py\gluon\restricted.py", line 212, in restricted
exec ccode in environment
File "D:\Google Drive\loic\web2py\web2py\applications\dommartin25\views\generic.rss", line 10, in <module>
from gluon.serializers import rss}}{{=XML(rss(response._vars
))}}
File "D:\Google Drive\loic\web2py\web2py\gluon\serializers.py", line 174, in rss

) for entry in feed.get('entries', [])])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)


I'm not a "python-master" like you, Niphlod and Sebastian, but would it be possible to make something like below in order not to break backward compatibility when one updates Web2py 2.4.5 to 2.4.7?
in seriaizers.py (this code doesn't work, it is just to explain my idea...)
def rss(feed):
   
if not 'entries' in feed and 'items' in feed:
        feed
['entries'] = feed['items']
    now
= datetime.datetime.now()
   
try:
        rss
= rss2.RSS2(title=str(feed.get('title', '(notitle)').encode('utf-8', 'replace')),

                        link
=str(feed.get('link', None).encode('utf-8', 'replace')),

                        description
=str(feed.get('description', '').encode('utf-8', 'replace')),
                        lastBuildDate
=feed.get('created_on', now),
                        items
=[rss2.RSSItem(
                               title
=str(entry.get('title', '(notitle)').encode('utf-8', 'replace')),
                               link
=str(entry.get('link', None).encode('utf-8', 'replace')),
                               description
=str(entry.get('description', '').encode('utf-8', 'replace')),
                               pubDate
=entry.get('created_on', now)

                               
) for entry in feed.get('entries', [])])

   
except Exception: #if an exception is raised, we use the former methon which works fine
        rss
= rss2.RSS2(title=str(feed.get('title', '(notitle)')),
                        link
=str(feed.get('link', None)),
                        description
=str(feed.get('description', '')),
                        lastBuildDate
=feed.get('created_on', now),
                        items
=[rss2.RSSItem(
                               title
=str(entry.get('title', '(notitle)')),
                               link
=str(entry.get('link', None)),
                               description
=str(entry.get('description', '')),
                               pubDate
=entry.get('created_on', now)

                               
) for entry in feed.get('entries', [])])

   
return rss.to_xml(encoding='utf-8')


Thank you 

Loïc

unread,
Jun 2, 2013, 8:16:25 AM6/2/13
to web...@googlegroups.com
Well,

I replaced python27/lib/xml/sax/saxutils.py with the patched file (see attached)
But I still have the same error :

Ticket ID

127.0.0.1.2013-06-02.14-13-25.c9feb7ca-4163-463e-ad44-185a7141dc9d

<type 'exceptions.UnicodeDecodeError'> 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)

Version

web2py™Version 2.4.7-stable+timestamp.2013.05.24.17.48.47
PythonPython 2.7.5: C:\Python27\python.exe (prefix: C:\Python27)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
Traceback (most recent call last):
File "D:\Google Drive\loic\web2py\web2py\gluon\restricted.py", line 212, in restricted
exec ccode in environment
File "D:\Google Drive\loic\web2py\web2py\applications\dommartin25\views\generic.rss", line 10, in <module>
from gluon.serializers import rss}}{{=XML(rss(response._vars))}}
File "D:\Google Drive\loic\web2py\web2py\gluon\serializers.py", line 174, in rss
) for entry in feed.get('entries', [])])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)

Any idea?
Thank you
saxutils.py

Loïc

unread,
Jun 4, 2013, 2:53:03 AM6/4/13
to web...@googlegroups.com
Hello all,
Am I the only one having issues with generic RSS views? Is there any workaround for my problem?
Thank you

Alexei Vinidiktov

unread,
Feb 15, 2014, 10:05:17 PM2/15/14
to web...@googlegroups.com
I'm having the same issue with rss in my InstantPress powered blog. I think it has the same roots.

I also replaced the saxutils.py file with the patched one and nothing changed.

Carlos Fillol Sendra

unread,
Mar 31, 2015, 6:27:34 PM3/31/15
to web...@googlegroups.com
Removing "str(" and ".encode('utf-8', 'replace'))" strings from rss function in gluon.serializers.py seems to solve the issue (at least it worked for me).

def rss(feed):
    if not 'entries' in feed and 'items' in feed:
        feed['entries'] = feed['items']
    now = datetime.datetime.now()
    rss = rss2.RSS2(title=feed.get('title', '(notitle)'),
                    link=feed.get('link', None),
                    description=feed.get('description', ''),
                    lastBuildDate=feed.get('created_on', now),
                    items=[rss2.RSSItem(
                           title=entry.get('title', '(notitle)'),
                           link=entry.get('link', None),
                           description=entry.get('description', ''),
                           pubDate=entry.get('created_on', now)
                           ) for entry in feed.get('entries', [])])
    return rss.to_xml(encoding='utf-8')

I'm using web2py 2.9.5 and Python 2.7.3.


Reply all
Reply to author
Forward
0 new messages