Skip to content

Commit bbc8e8f

Browse files
authored
Try to detect when users need to Install Certificates on Mac (realpython#16)
* Point users to Install Certificates on Mac * Use error message to detect certificate issue * Remove outdated noqa comment
1 parent 9f3a18d commit bbc8e8f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/reader/feed.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Interact with the Real Python feed."""
22
# Standard library imports
3-
from typing import Dict, List # noqa
3+
from typing import Dict, List
44

55
# Third party imports
66
import feedparser
@@ -21,8 +21,17 @@ def _feed(url: str = URL) -> feedparser.FeedParserDict:
2121

2222
def get_site(url: str = URL) -> str:
2323
"""Get name and link to website of the feed."""
24-
info = _feed(url).feed
25-
return f"{info.title} ({info.link})"
24+
info = _feed(url)
25+
if exception := info.get("bozo_exception"):
26+
message = f"Could not read feed at {url}"
27+
if "CERTIFICATE_VERIFY_FAILED" in str(exception):
28+
message += (
29+
".\n\nYou may need to manually install certificates by running "
30+
"`Install Certificates` in your Python installation folder. "
31+
"See https://realpython.com/installing-python/"
32+
)
33+
raise SystemExit(message)
34+
return f"{info.feed.title} ({info.feed.link})"
2635

2736

2837
def get_article(article_id: str, links: bool = False, url: str = URL) -> str:

0 commit comments

Comments
 (0)