Home Assistant release with the issue: 0.84.6
Last working Home Assistant release (if known): n/a
Operating environment (Hass.io/Docker/Windows/etc.): Arch Linux
Component/platform: Discord
Description of problem: When attempting to send a notification via the Discord notifier, a SyntaxError exception is raised.
Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):
configuration.yaml:
...
notify: !include notifications.yaml
...
nofitications.yaml
- name: discord
platform: discord
token: <censored_token>
From the Services tab in the developer tools:
Service: notification.discord
Seervice Data: {"message":"test","target":["<censored_target>"]}
Traceback (if applicable):
2019-01-03 20:59:22 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140094592835200] Received {'type': 'call_service', 'domain': 'notify', 'service': 'discord', 'service_data': {'message': 'test', 'target': '<censored_target>'}, 'id': 19}
2019-01-03 20:59:22 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=notify, service=discord, service_data=message=test, target=<censored_target>>
2019-01-03 20:59:22 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.140094592835200] Error handling message: {'type': 'call_service', 'domain': 'notify', 'service': 'discord', 'service_data': {'message': 'test', 'target': '<censored_target>'}, 'id': 19}
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/homeassistant/components/websocket_api/decorators.py", line 16, in _handle_async_response
await func(hass, connection, msg)
File "/usr/lib/python3.7/site-packages/homeassistant/components/websocket_api/commands.py", line 148, in handle_call_service
connection.context(msg))
File "/usr/lib/python3.7/site-packages/homeassistant/core.py", line 1121, in async_call
self._execute_service(handler, service_call))
File "/usr/lib/python3.7/site-packages/homeassistant/core.py", line 1143, in _execute_service
await handler.func(service_call)
File "/usr/lib/python3.7/site-packages/homeassistant/components/notify/__init__.py", line 117, in async_notify_message
await notify_service.async_send_message(**kwargs)
File "/usr/lib/python3.7/site-packages/homeassistant/components/notify/discord.py", line 43, in async_send_message
import discord
File "/var/lib/hass/deps/lib/python3.7/site-packages/discord/__init__.py", line 20, in <module>
from .client import Client, AppInfo, ChannelPermissions
File "/var/lib/hass/deps/lib/python3.7/site-packages/discord/client.py", line 42, in <module>
from .voice_client import VoiceClient
File "/var/lib/hass/deps/lib/python3.7/site-packages/discord/voice_client.py", line 43, in <module>
import websockets
File "/var/lib/hass/deps/lib/python3.7/site-packages/websockets/__init__.py", line 3, in <module>
from .client import *
File "/var/lib/hass/deps/lib/python3.7/site-packages/websockets/client.py", line 12, in <module>
from .protocol import CONNECTING, OPEN, WebSocketCommonProtocol
File "/var/lib/hass/deps/lib/python3.7/site-packages/websockets/protocol.py", line 17, in <module>
from .compatibility import asyncio_ensure_future
File "/var/lib/hass/deps/lib/python3.7/site-packages/websockets/compatibility.py", line 9
asyncio_ensure_future = asyncio.async # Python < 3.5
^
SyntaxError: invalid syntax
Additional information:
Possibly related to https://github.com/home-assistant/home-assistant/issues/16644.
Initial HA Discord conversation here.
Workaround:
Edit /var/lib/hass/deps/lib/python3.7/site-packages/websockets/compatibility.py, and change line 6 from...
asyncio_ensure_future = asyncio.async # Python < 3.5
...to...
asyncio_ensure_future = getattr(asyncio, 'async') # Python < 3.5
The Discord component requires discord.py version 0.16.12 explicitly:
https://github.com/home-assistant/home-assistant/blob/ead38f60054162cd73e19ecf453e8b7933e82f14/homeassistant/components/notify/discord.py#L18
discord.py's requirements.txt requires websockets >=3.1,<4.0:
https://github.com/Rapptz/discord.py/blob/1863a1c6636f53592519320a173ec9573c090c0b/requirements.txt#L2
And if you look at the websockets releases, the latest tag resolves to version 3.4. This is where asyncio.sync lives:
https://github.com/aaugustin/websockets/blob/e812f02d30d930eb802e0439a397431880bad5f1/websockets/compatibility.py#L9
The fix for this issue was added in this commit, and is part of release 5.0:
https://github.com/aaugustin/websockets/commit/9f566c5d12eae1258aa6f1991fe8cf0a7d390f97
So I think the solution would be to attempt to version bump discord.py's websockets dependency to at least 5.0, cut a new release of discord.py, then require it in the HA discord component.
Related PR of interest: https://github.com/Rapptz/discord.py/pull/1111
It also appears that this error is specific to Python 3.7. Python 3.6 seems to work fine.
So I think the solution would be to attempt to version bump discord.py's websockets dependency to at least 5.0, cut a new release of discord.py, then require it in the HA discord component.
Note: The rewrite branch of discord.py has the websockets requirement as >=6.0,<7.0
Also see https://github.com/Rapptz/discord.py/issues/1249 and https://github.com/Rapptz/discord.py/issues/1401
It also appears that this error is specific to Python 3.7. Python 3.6 seems to work fine.
This is because async became a keyword in Python 3.7
I just started having this error on 0.88.0b0 on Hass.io (qemuarm-64).
Traceback:
Error while executing automation automation.notify_that_front_door_closed. Unknown error for call_service at pos 1:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/homeassistant/components/automation/__init__.py", line 375, in action
await script_obj.async_run(variables, context)
File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py", line 131, in async_run
await self._handle_action(action, variables, context)
File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py", line 210, in _handle_action
action, variables, context)
File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py", line 299, in _async_call_service
context=context
File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 85, in async_call_from_config
domain, service_name, service_data, blocking=blocking, context=context)
File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1130, in async_call
self._execute_service(handler, service_call))
File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1152, in _execute_service
await handler.func(service_call)
File "/usr/local/lib/python3.7/site-packages/homeassistant/components/notify/__init__.py", line 117, in async_notify_message
await notify_service.async_send_message(**kwargs)
File "/usr/local/lib/python3.7/site-packages/homeassistant/components/notify/discord.py", line 43, in async_send_message
import discord
File "/usr/local/lib/python3.7/site-packages/discord/__init__.py", line 20, in <module>
from .client import Client, AppInfo, ChannelPermissions
File "/usr/local/lib/python3.7/site-packages/discord/client.py", line 38, in <module>
from .state import ConnectionState
File "/usr/local/lib/python3.7/site-packages/discord/state.py", line 36, in <module>
from . import utils, compat
File "/usr/local/lib/python3.7/site-packages/discord/compat.py", line 32
create_task = asyncio.async
^
SyntaxError: invalid syntax
Read you errors.
Same issue on docker & raspberry on latest version
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 馃憤
This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Note: The rewrite branch of discord.py has the websockets requirement as >=6.0,<7.0
Also see https://github.com/Rapptz/discord.py/issues/1249 and https://github.com/Rapptz/discord.py/issues/1401
This is because
asyncbecame a keyword in Python 3.7