Feed has a 302 redirect but feedparser throws AttributeError: 'NoneType' object has no attribute 'status'
Closed this issue · 2 comments
samuelclay commented
This feed is not actually a feed but rather a 302 redirect. But the 302 is missing the Location
header which would then be used by feed parser. Instead, we get an AttributeError
:
>>> import feedparser
>>> fp = feedparser.parse('http://tools.microformatic.com/transcode/rss/hatom/http://fusesource.com')
Traceback (most recent call last):
File "/usr/local/lib/python3.9/code.py", line 90, in runcode
exec(code, self.locals)
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/feedparser/api.py", line 214, in parse
data = _open_resource(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers, result)
File "/usr/local/lib/python3.9/site-packages/feedparser/api.py", line 114, in _open_resource
return http.get(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers, result)
File "/usr/local/lib/python3.9/site-packages/feedparser/http.py", line 158, in get
f = opener.open(request)
File "/usr/local/lib/python3.9/urllib/request.py", line 523, in open
response = meth(req, response)
File "/usr/local/lib/python3.9/urllib/request.py", line 632, in http_response
response = self.parent.error(
File "/usr/local/lib/python3.9/urllib/request.py", line 555, in error
result = self._call_chain(*args)
File "/usr/local/lib/python3.9/urllib/request.py", line 494, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.9/site-packages/feedparser/http.py", line 56, in http_error_301
result.status = code
AttributeError: 'NoneType' object has no attribute 'status'
Here's the feed headers:
$ curl -I -i http://tools.microformatic.com/transcode/rss/hatom/http://fusesource.com
HTTP/1.1 302 Found
Date: Wed, 03 Mar 2021 19:12:55 GMT
Server: Apache/2.4.27 (Ubuntu)
X-Powered-By: PHP/7.1.17-0ubuntu0.17.10.1
Content-Length: 0
Content-Type: application/atom+xml
X-Varnish: 167118621 167614797
Age: 24
Via: 1.1 varnish (Varnish/5.0)
X-Cache: HIT
Connection: keep-alive
Should feedparser be able to handle a broken feed that's broken like this?
kurtmckee commented
Well, requests
doesn't choke on it, probably feedparser shouldn't either. I'll see what I can do!
kurtmckee commented
Samuel, this should be fixed in feedparser 6.0.6. Thanks for reporting this!