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 script/entrypoint discord_webhook tries to create the DiscordWebhook using a list of urls #162

Open
fizmat opened this issue Dec 18, 2024 · 0 comments

Comments

@fizmat
Copy link

fizmat commented Dec 18, 2024

The --url argument allows multiple values ('+'), so args.url is actually a list of strings (even when given only one --url):

But the DiscordWebhook accepts only one str url in the constuctor

def __init__(self, url: str, **kwargs) -> None:

It does not fail in the constructor, but when trying to connect it passes the list to requests and that fails:

.\python\Scripts\discord_webhook.exe --url "https://discord.com/api/webhooks/*redacted*" -c "asdf"
Traceback (most recent call last):
  File "*redacted*\python\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "*redacted*\python\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "*redacted*\python\Scripts\discord_webhook.exe\__main__.py", line 7, in <module>
  File "*redacted*\python\lib\site-packages\discord_webhook\__main__.py", line 33, in main
    return webhook.execute() is not None
  File "*redacted*\python\lib\site-packages\discord_webhook\webhook.py", line 444, in execute
    response = self.api_post_request()
  File "*redacted*\python\lib\site-packages\discord_webhook\webhook.py", line 388, in api_post_request
    return requests.post(
  File "*redacted*\python\lib\site-packages\requests\api.py", line 115, in post
    return request("post", url, data=data, json=json, **kwargs)
  File "*redacted*\python\lib\site-packages\requests\api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "*redacted*\lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "*redacted*\python\lib\site-packages\requests\sessions.py", line 697, in send
    adapter = self.get_adapter(url=request.url)
  File "*redacted*\python\lib\site-packages\requests\sessions.py", line 792, in get_adapter
    raise InvalidSchema(f"No connection adapters were found for {url!r}")
requests.exceptions.InvalidSchema: No connection adapters were found for "['https://discord.com/api/webhooks/*redacted*']"

You can

  1. drop CLI: if nobody noticed that it doesn't work, is it even useful?
  2. only allow one --url: it's very simple to do and probably enough for a minimal CLI
  3. rewrite CLI and use provided urls sequentially: is simple, but requires some work
  4. rewrite CLI and use provided urls sequentially, but send in parallel if discord_webhook[async] is installed: it's probably overkill
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

1 participant