home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.14k stars 29.82k forks source link

Octoprint component doesn't load with disconnected printer. #10557

Closed DuckY1987 closed 6 years ago

DuckY1987 commented 6 years ago

Unfortunately, the octoprint component doesn't load when my printer is switched off (disconnected to the pi)

To reproduce the issue, just disconnect the power cord from your 3d printer which is serial connected to a pi which runs octoprint.

After restarting hass, the comp failed to load, could you fix this?

Thanks.

w1ll1am23 commented 6 years ago

This is already fixed. You need to set the bed and number_of_tools in your config. Check the docks here https://home-assistant.io/components/octoprint/

DuckY1987 commented 6 years ago

thats not the problem, i configured both values already.

the Problem is when i disconnect the printer via USB from the octoprint server which runs on an own raspberry pi and restart hass, i end up in errors as the component cant read the values i assume.

api_key: !secret octoprint bed: true number_of_tools: 1

I have a sonoff pow between the power supply and the 3d printer, so i switch it remotely via hass off when i dont need the printer.

When i change the configuration and restart hass i run always into an unloaded component.

It was marked as fixed: #8978

w1ll1am23 commented 6 years ago

Can you provide logs? I tested this the other day and it wormed for me. At start up of the printer isn't there, you do still get an initial error message, but if you plug the printer back in (and connected it to the octoprint software) it should start reporting.

kbrint commented 6 years ago

I am having the same issue with HomeAssistant version 0.58.1 and OctoPrint version 1.3.5.

The OctoPrint API produces the following when the printer is off:

% curl -i -H "X-Api-Key: blah" http://octopi/api/printer
HTTP/1.1 409 CONFLICT
Content-Type: text/html; charset=utf-8
Content-Length: 26
Cache-Control: max-age=0
X-Clacks-Overhead: GNU Terry Pratchett
Set-Cookie: session_P80=some blahblah; Path=/; HttpOnly
X-Robots-Tag: noindex, nofollow, noimageindex

Printer is not operational

Note that the output terminates after "operational"; there is no newline.

Here is what my HomeAssistant logs show:

2017-11-26 14:43:35 ERROR (Thread-5) [homeassistant.components.octoprint] True 1
2017-11-26 14:43:35 ERROR (MainThread) [homeassistant.setup] Error during setup of component octoprint
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py", line 193, in _async_setup_component
    component.setup, hass, processed_config)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/octoprint.py", line 45, in setup
    octoprint_api.get('printer')
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/octoprint.py", line 107, in get
    response.raise_for_status()
  File "/srv/homeassistant/lib/python3.5/site-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 409 Client Error: CONFLICT for url: http://octopi.home.rufus.net/api/printer
2017-11-26 14:43:35 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of binary_sensor.octoprint. Setup failed for dependencies: octoprint
2017-11-26 14:43:35 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform binary_sensor.octoprint: Could not setup all dependencies.

And finally, my config:

octoprint:
   host: octopi.home.rufus.net
   api_key: !secret octoprint_api_key
   bed: true
   number_of_tools: 1

binary_sensor:
  - platform: octoprint
    monitored_conditions:
     - Printing
     - Printing Error
w1ll1am23 commented 6 years ago

@kbrint I don't understand what is happening here my config matches your, the only difference being I have bed set to false The error you are getting on line 107 is already being caught so I don't understand why you are getting it an I am not.

        try:
            response = requests.get(
                url, headers=self.headers, timeout=9)
            response.raise_for_status()
            if endpoint == "job":
                self.job_last_reading[0] = response.json()
                self.job_last_reading[1] = time.time()
                self.job_available = True
            elif endpoint == "printer":
                self.printer_last_reading[0] = response.json()
                self.printer_last_reading[1] = time.time()
                self.printer_available = True
            self.available = self.printer_available and self.job_available
            if self.available:
                self.job_error_logged = False
                self.printer_error_logged = False
            return response.json()
        except (requests.exceptions.ConnectionError,
-->                requests.exceptions.HTTPError,
                requests.exceptions.ReadTimeout) as conn_exc:

I am running OctoPrint 1.3.5 and HA 0.59 dev. I have octoprint running but the printer unplugged and I get the same response from cURL that you did.

What version of requests do you have installed?

pip freeze | grep "requests"

mine is 2.18.4

kbrint commented 6 years ago
%  pip freeze | grep requests
requests==2.18.4

I get the same problem with bed=false.

0.58.1 looks to include commit 652c006cb, which claims to fix. Let me know if there is any other info you need.

w1ll1am23 commented 6 years ago

It was actually fixed with 06a20d0d1 but still that has been there for awhile.

DuckY1987 commented 6 years ago

Hey there,

just updated to the latest release of hass, unfortunately i get still the same error in the log:

response = self.get(end_point)

File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 104, in get response.raise_for_status() File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 928, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 409 Client Error: CONFLICT for url: http://172.17.0.170/api/printer

Version: requests==2.18.4

Error API from the octoprint api:

HTTP/1.1 409 CONFLICT Content-Type: text/html; charset=utf-8 Content-Length: 26 Cache-Control: max-age=0 X-Clacks-Overhead: GNU Terry Pratchett Set-Cookie: session_P80=blah; Path=/; HttpOnly X-Robots-Tag: noindex, nofollow, noimageindex

Octoprint version 1.3.5

DuckY1987 commented 6 years ago

Now its spaming my log after i switched the sonoff off:

ERROR:homeassistant.helpers.entity:Update for binary_sensor.octoprint_printing fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/binary_sensor/octoprint.py", line 94, in update
    self.api_tool)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 144, in update
    response = self.get(end_point)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 107, in get
    response.raise_for_status()
  File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 409 Client Error: CONFLICT for url: http://172.17.0.170/api/printer
ERROR:homeassistant.helpers.entity:Update for binary_sensor.octoprint_printing_error fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/binary_sensor/octoprint.py", line 94, in update
    self.api_tool)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 144, in update
    response = self.get(end_point)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 107, in get
    response.raise_for_status()
  File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 409 Client Error: CONFLICT for url: http://172.17.0.170/api/printer
ERROR:homeassistant.helpers.entity:Update for sensor.octoprint_target_bed_temp fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/octoprint.py", line 130, in update
    self.api_tool)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 144, in update
    response = self.get(end_point)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 107, in get
    response.raise_for_status()
  File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 409 Client Error: CONFLICT for url: http://172.17.0.170/api/printer
ERROR:homeassistant.helpers.entity:Update for sensor.octoprint_actual_tool0_temp fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/octoprint.py", line 130, in update
    self.api_tool)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 144, in update
    response = self.get(end_point)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 107, in get
    response.raise_for_status()
  File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 409 Client Error: CONFLICT for url: http://172.17.0.170/api/printer
ERROR:homeassistant.helpers.entity:Update for sensor.octoprint_target_tool0_temp fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/octoprint.py", line 130, in update
    self.api_tool)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 144, in update
    response = self.get(end_point)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 107, in get
    response.raise_for_status()
  File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 409 Client Error: CONFLICT for url: http://172.17.0.170/api/printer
ERROR:homeassistant.helpers.entity:Update for sensor.octoprint_current_state fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/octoprint.py", line 130, in update
    self.api_tool)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 144, in update
    response = self.get(end_point)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 107, in get
    response.raise_for_status()
  File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 409 Client Error: CONFLICT for url: http://172.17.0.170/api/printer
ERROR:homeassistant.helpers.entity:Update for sensor.octoprint_actual_bed_temp fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/octoprint.py", line 130, in update
    self.api_tool)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 144, in update
    response = self.get(end_point)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/octoprint.py", line 107, in get
    response.raise_for_status()
  File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 409 Client Error: CONFLICT for url: http://172.17.0.170/api/printer
w1ll1am23 commented 6 years ago

Any chance you can try upgrading python to 3.6? If not I can try to recreate this with 3.5 later tonight. I have only ever run 3.4 and 3.6 so maybe it's a 3.5 issue?

Landrash commented 6 years ago

@w1ll1am23 Just FYI. Raspbian and most Debian based raspberry Pi distributions only have Python 3.5 available.

filcole commented 6 years ago

I'm also getting this on raspbian. It seems that requests.exceptions.HTTPError is not being caught.
Hacking the exception handling from

except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError, requests.exceptions.ReadTimeout) as conn_exc: to

except Exception as conn_exc:

makes it "work" and the requests.exceptions.HTTPError exception is caught. It's definetly HTTPError that's not being caught because it still returned via type(conn_exc) even when caught via Exception.

w1ll1am23 commented 6 years ago

@filcole Thanks for the update I forgot about this issue. I am going to page in some more experienced devs and see if they have any idea what is going on.

@MartinHjelmare @balloob - Can either of you explain what is happening here? To summarize, some users are seeing this Trackback and others aren't. For some reason the exception requests.exceptions.HTTPError isn't being caught for some users but is for others. How is that possible?

vMeph commented 6 years ago

runing hassio getting this error when printer not connected Error: 409 Client Error: CONFLICT for url: http://192.168.1.23/api/printer any fix?

kbrint commented 6 years ago

vMeph: upgrade to 0.61 or later fixed it for me. Now when the Octoprint API returns a 409, Hass knows that it's not printing.