Python rss feed gets AttributeError

61 views Asked by At

Running this code:

import feedparser

Feed = feedparser.parse('http://www.reddit.com/r/python/.rss')
pointer = Feed.entries[1]
print (pointer.summary)
print (pointer.link)

I get this error:

AttributeError: partially initialized module 'feedparser' has no attribute '__version__' (most likely due to a circular import)

I'm using Idle on a Mac, but I get the same error running in Terminal.

1

There are 1 answers

6
J_H On

I cannot reproduce your symptom.

Using feedparser 6.0.10 under cPython 3.10.8 and macos 12.6.2 your 1st print says:

<!-- SC_OFF --><div class="md"><p>Discussion of using Python in a professional environment, getting jobs in Python as well as ask questions about courses to further your python education!</p> <p><strong>This thread is not for recruitment, please see</strong> <a href="https://www.reddit.com/r/PythonJobs">r/PythonJobs</a> <strong>or the thread in the sidebar for that.</strong></p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Im__Joseph"> /u/Im__Joseph </a> <br /> <span><a href="https://www.reddit.com/r/Python/comments/109k9to/thursday_daily_thread_python_careers_courses_and/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/Python/comments/109k9to/thursday_daily_thread_python_careers_courses_and/">[comments]</a></span>

and your 2nd print says

https://www.reddit.com/r/Python/comments/109k9to/thursday_daily_thread_python_careers_courses_and/

Use $ python -m site to verify that sys.path points to where you think it should, and that you've installed just a single feedparser library there. Consider nuking your venv and doing pip installs from scratch.

It is possible that you showed us just an excerpt from a larger codebase. Read your posted question and try to reproduce the symptom -- copy-n-paste those few lines of code into a new file and run that. Or use example code from the docs, which is very similar. It sounds like your install can't even support $ python -c 'import feedparser' yet.