diff options
| author | 2020-12-20 10:31:43 +0200 | |
|---|---|---|
| committer | 2020-12-20 10:31:43 +0200 | |
| commit | d55adafde54d6b695f6e2ba91c3813c45ea95d0e (patch) | |
| tree | 98a3541842a17a19c7ec035785eb228fd8362f87 | |
| parent | Log warning and return early when can't get PEP URLs from API (diff) | |
Implement GitHub API authorization header
| -rw-r--r-- | bot/exts/utils/pep.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/bot/exts/utils/pep.py b/bot/exts/utils/pep.py index d642c902a..df9ad2ba9 100644 --- a/bot/exts/utils/pep.py +++ b/bot/exts/utils/pep.py @@ -8,6 +8,7 @@ from discord import Colour, Embed from discord.ext.commands import Cog, Context, command from bot.bot import Bot +from bot.constants import Keys from bot.utils.cache import AsyncCache log = logging.getLogger(__name__) @@ -16,6 +17,10 @@ ICON_URL = "https://www.python.org/static/opengraph-icon-200x200.png" pep_cache = AsyncCache() +GITHUB_API_HEADERS = {} +if Keys.github: + GITHUB_API_HEADERS["Authorization"] = f"token {Keys.github}" + class PythonEnhancementProposals(Cog): """Cog for displaying information about PEPs.""" @@ -38,7 +43,10 @@ class PythonEnhancementProposals(Cog): log.trace("Started refreshing PEP URLs.") self.last_refreshed_peps = datetime.now() - async with self.bot.http_session.get(self.PEPS_LISTING_API_URL) as resp: + async with self.bot.http_session.get( + self.PEPS_LISTING_API_URL, + headers=GITHUB_API_HEADERS + ) as resp: if resp.status != 200: log.warning(f"Fetching PEP URLs from GitHub API failed with code {resp.status}") return |