Octoprint "Unexpected error"

Hi all,

As Octoprint has moved from YAML to GUI as of 2021.11, I’m trying to re-add the integration to my Home Assistant after removing the YAML configuration. I’m running into some problems here as the GUI comes back with 'Unexpected error" after clicking “Allow” in OctoPrint. In OctoPrint, a registered application key is added nevertheless.

Via the log I’ve been able to get the following information:

Failed to get an application key: Application key creation request has been denied or timed out

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/octoprint/config_flow.py", line 99, in async_step_get_api_key
    await self.api_key_task
  File "/usr/src/homeassistant/homeassistant/components/octoprint/config_flow.py", line 191, in _async_get_auth_key
    user_input[CONF_API_KEY] = await octoprint.request_app_key(
  File "/usr/local/lib/python3.9/site-packages/pyoctoprintapi/octoprint_client.py", line 33, in request_app_key
    status_response = await self._api.appkeys_check_status(request_id)
  File "/usr/local/lib/python3.9/site-packages/pyoctoprintapi/api.py", line 81, in appkeys_check_status
    raise ApiError("Application key creation request has been denied or timed out")
pyoctoprintapi.exceptions.ApiError: Application key creation request has been denied or timed out

These are the settings in the GUI I use for setup:

**Username**: sandolution
**Host**: 3d_printer.lan
**Port Number**: 80
**Application Path**: /
**SSL**: Not checked

Versions used

**OctoPrint**: 1.7.2 (latest)
**Home Assistant**: 2021.11.1 (latest)
**Supervisor**: 2021-10.8 (latest)
**HassOS**: 6.6 (latest)

Any thoughts on why this error comes up? Are there more people experiencing this?
If needed, I can open a bug report.

Cheers,
Sander

Hi there, instead of the native octoprint integration, I think that it is better to use the HomeAssistant Discovery plugin in octoprint and use mqtt discovery to add the device. With this method, there are more sensors inbuilt and also there is option to add more custom sensors as mqtt sensors.

Hope you could try it out. If you want to add camera, just use the generic camera integration.

^This works like a charm and as stated gives you a ton of sensors

Sound like a valid option, I’ll definitely look into that! Thanks for sharing.
Nevertheless, the official integration should work properly as well, shouldn’t it?

1 Like

Actually I haven’t seen such an error being reported with octoprint integration. You could open a bug report to get developer assistance. Also i haven’t used the native integration till now because I find the other more useful.

Maybe a longshot but I kinda remember octoprint stating that the global API key was being deprecated on a newer version could that be your issue?

1 Like

Seems that a bug report is already opened:

I’ll add my findings there as well, and post back here when the solution is found.

2 Likes

I was having the same issue and found that in my OctoPrint, the bundled discovery plugin was disabled. Enabling this plugin allowed me to add it to home assistant using the integrations GUI

2 Likes