RSS feed not working due to Content Length Mismatch error
See original GitHub issueI have just installed puput==0.9.1
as an app alongside the rest of my Django site, and I have noticed the RSS feed is not working.
The server appears to be serving the page OK:
127.0.0.1 - - [09/Nov/2017 22:23:15] "GET /news/feed/ HTTP/1.1" 200 -
INFO _internal 127.0.0.1 - - [09/Nov/2017 22:23:15] "GET /news/feed/ HTTP/1.1" 200 -
But the browser (Chromium) reports:
This page isn’t working
localhost unexpectedly closed the connection.
ERR_CONTENT_LENGTH_MISMATCH
Note the content length mismatch error.
When I use the debugger to see the response to the syndication view I can see good data:
> /home/paul/dev/Syncables/.venv/lib/python3.5/site-packages/django/contrib/syndication/views.py(41)__call__()
-> feedgen = self.get_feed(obj, request)
(Pdb) pp request
<WSGIRequest: GET '/news/feed/'>
(Pdb) n
> /home/paul/dev/Syncables/.venv/lib/python3.5/site-packages/django/contrib/syndication/views.py(42)__call__()
-> response = HttpResponse(content_type=feedgen.content_type)
(Pdb) pp feedgen
<puput.feeds.BlogPageFeedGenerator object at 0x7f4c843dcc50>
(Pdb) pp feedgen.content_type
'application/rss+xml; charset=utf-8'
(Pdb) dir(feedgen)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_version', 'add_item', 'add_item_elements', 'add_root_elements', 'content_type', 'endChannelElement', 'feed', 'item_attributes', 'items', 'latest_post_date', 'mime_type', 'num_items', 'root_attributes', 'rss_attributes', 'write', 'writeString', 'write_items']
(Pdb) pp feedgen.items
[{'author_email': None,
'author_link': None,
'author_name': None,
'categories': (),
'comments': None,
'description': '<p>Here is some more content</p>',
'enclosures': [],
'item_copyright': None,
'link': 'https://localhost:8000/news/2017/11/09/my-2nd-post/',
'pubdate': datetime.datetime(2017, 11, 9, 14, 3, tzinfo=<UTC>),
'title': 'This is my 2nd post',
'ttl': None,
'unique_id': 'https://localhost:8000/news/2017/11/09/my-2nd-post/',
'unique_id_is_permalink': None,
'updateddate': None},
{'author_email': None,
'author_link': None,
'author_name': None,
'categories': (),
'comments': None,
'description': '<p>This is the body of the blog</p>',
'enclosures': [],
'item_copyright': None,
'link': 'https://localhost:8000/news/2017/11/09/my-first-blog-post/',
'pubdate': datetime.datetime(2017, 11, 9, 13, 29, tzinfo=<UTC>),
'title': 'This is my first blog post',
'ttl': None,
'unique_id': 'https://localhost:8000/news/2017/11/09/my-first-blog-post/',
'unique_id_is_permalink': None,
'updateddate': None}]
...
(Pdb) print(response.content.decode('utf-8'))
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>News</title><link>https://example.com/news/</link><description>All the news about Syncables products and services</description><atom:link rel="self" href="https://example.com/news/feed/"></atom:link><language>en-gb</language><lastBuildDate>Thu, 09 Nov 2017 14:03:00 +0000</lastBuildDate><item><title>This is my 2nd post</title><link>https://localhost:8000/news/2017/11/09/my-2nd-post/</link><description><p>Here is some more content</p></description><pubDate>Thu, 09 Nov 2017 14:03:00 +0000</pubDate><guid>https://localhost:8000/news/2017/11/09/my-2nd-post/</guid></item><item><title>This is my first blog post</title><link>https://localhost:8000/news/2017/11/09/my-first-blog-post/</link><description><p>This is the body of the blog</p></description><pubDate>Thu, 09 Nov 2017 13:29:00 +0000</pubDate><guid>https://localhost:8000/news/2017/11/09/my-first-blog-post/</guid></item></channel></rss>
...
So this appears to be an issue with the way Django is handling the response successfully generated by Putput. This is using Django==1.11.4
.
I checked the RSS XML output above in the RSS feed checker, and it validated OK with the exception of
example.com
in the <link>
. Don’t know where this comes from but it would appear to be a separate issue.
This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.
line 2, column 263: Self reference doesn't match document location [help]
... " href="https://example.com/news/feed/"></atom:link><language>en-gb</lan ...
Any ideas?
Which part of Django is responsible for setting the correct content length for a response object?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top GitHub Comments
@marctc Sorry, no. Switched away from Puput/Wagtail to Pinax due to the various issues I encountered.
On 15/02/18 16:49, Marc Tudurí wrote:
If the issue still exists please re-open