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

The `!docs` command is failing as it's unable to make requests #727

Closed
SebastiaanZ opened this issue Jan 13, 2020 · 3 comments · Fixed by #728
Closed

The `!docs` command is failing as it's unable to make requests #727

SebastiaanZ opened this issue Jan 13, 2020 · 3 comments · Fixed by #728

Comments

@SebastiaanZ
Copy link
Member

@SebastiaanZ SebastiaanZ commented Jan 13, 2020

Currently, the !docs command is completely broken as intersphinx is unable to form a proper request. I haven't looked deeply into the issue yet, but it seems like there's an internal error in how intersphinx forms the request. The user_agent of the config it passes does not seem to exist, while requests expects such an attribute to be there:

Jan 13 08:09:17 Bot: |            bot.cogs.error_handler |    ERROR | Error executing command invoked by Ves Zappa#3787: +docs refresh
Ignoring exception in on_command_error
Traceback (most recent call last):
  File "/home/sebastiaan/.local/share/virtualenvs/djangobot-Py5o4YeS/lib/python3.7/site-packages/discord/client.py", line 270, in _run_event
    await coro(*args, **kwargs)
  File "/home/sebastiaan/pydis/repositories/djangobot/bot/cogs/error_handler.py", line 139, in on_command_error
    await self.handle_unexpected_error(ctx, e.original)
  File "/home/sebastiaan/pydis/repositories/djangobot/bot/cogs/error_handler.py", line 153, in handle_unexpected_error
    raise e
  File "/home/sebastiaan/.local/share/virtualenvs/djangobot-Py5o4YeS/lib/python3.7/site-packages/discord/ext/commands/core.py", line 79, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/sebastiaan/pydis/repositories/djangobot/bot/cogs/doc.py", line 463, in refresh_command
    await self.refresh_inventory()
  File "/home/sebastiaan/pydis/repositories/djangobot/bot/cogs/doc.py", line 234, in refresh_inventory
    await asyncio.gather(*coros)
  File "/home/sebastiaan/pydis/repositories/djangobot/bot/cogs/doc.py", line 181, in update_single
    package = await self._fetch_inventory(inventory_url, config)
  File "/home/sebastiaan/pydis/repositories/djangobot/bot/cogs/doc.py", line 484, in _fetch_inventory
    package = await self.bot.loop.run_in_executor(None, fetch_func)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/sebastiaan/.local/share/virtualenvs/djangobot-Py5o4YeS/lib/python3.7/site-packages/sphinx/ext/intersphinx.py", line 162, in fetch_inventory
    f = _read_from_url(inv, config=app.config)
  File "/home/sebastiaan/.local/share/virtualenvs/djangobot-Py5o4YeS/lib/python3.7/site-packages/sphinx/ext/intersphinx.py", line 118, in _read_from_url
    r = requests.get(url, stream=True, config=config, timeout=config.intersphinx_timeout)
  File "/home/sebastiaan/.local/share/virtualenvs/djangobot-Py5o4YeS/lib/python3.7/site-packages/sphinx/util/requests.py", line 129, in get
    headers.setdefault('User-Agent', _get_user_agent(config))
  File "/home/sebastiaan/.local/share/virtualenvs/djangobot-Py5o4YeS/lib/python3.7/site-packages/sphinx/util/requests.py", line 111, in _get_user_agent
    if config.user_agent:
AttributeError: ('intersphinx inventory %r not fetchable due to %s: %s', 'https://docs.python.org/3/objects.inv', <class 'AttributeError'>, "'DummyObject' object has no attribute 'user_agent'")

We've recently merged a PR (#715) relating to the !docs command, so that's worth looking into. Another option would be to look into the versions we're using and if anything has changed there. I'm currently not in a position to do so, but I'll do some probing later if no one else has done so yet.

@SebastiaanZ

This comment has been minimized.

Copy link
Member Author

@SebastiaanZ SebastiaanZ commented Jan 13, 2020

Another option would be the recent version bump of sphinx to 2.3.1 in the latest commit to master. While our requests version should be compatible (according to the setup.py of sphinx), maybe it actually isn't. I'll try to revert locally to see what happens.

@Numerlor

This comment has been minimized.

Copy link
Contributor

@Numerlor Numerlor commented Jan 13, 2020

The latest version of sphinx included a default value for the user_agent, making it a required argument of the config.
Our current way to make a config is a simple python object with attributes assigned to it, which wasn't updated accordingly.

bot/bot/cogs/doc.py

Lines 105 to 114 in ae9018e

class DummyObject(object):
"""A dummy object which supports assigning anything, which the builtin `object()` does not support normally."""
class SphinxConfiguration:
"""Dummy configuration for use with intersphinx."""
config = DummyObject()
config.intersphinx_timeout = 3
config.tls_verify = True

@SebastiaanZ

This comment has been minimized.

Copy link
Member Author

@SebastiaanZ SebastiaanZ commented Jan 13, 2020

Thanks. Adding a user_agent attribute does seem to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.