Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feed has a 302 redirect but feedparser throws AttributeError: 'NoneType' object has no attribute 'status' #267

Closed
samuelclay opened this issue Mar 3, 2021 · 2 comments

Comments

@samuelclay
Copy link

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?

@samuelclay samuelclay changed the title Feed has a 302 redirect but feed parser throws AttributeError: 'NoneType' object has no attribute 'status' Feed has a 302 redirect but feedparser throws AttributeError: 'NoneType' object has no attribute 'status' Mar 3, 2021
@kurtmckee
Copy link
Owner

Well, requests doesn't choke on it, probably feedparser shouldn't either. I'll see what I can do!

kurtmckee added a commit that referenced this issue Jun 15, 2021
@kurtmckee
Copy link
Owner

Samuel, this should be fixed in feedparser 6.0.6. Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants