stianaske / pybotvac

Python module for interacting with Neato Botvac Connected vacuum robots.
MIT License
85 stars 44 forks source link

Crash when listing robots #18

Closed bphermansson closed 3 years ago

bphermansson commented 6 years ago

Hi!

Gets this message when I try to use the code:


$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pybotvac import Account
>>> for robot in Account('hermansson.patrik@gmail.com', '<hidden>').robots: print(robot)
... 
/usr/lib/python3/dist-packages/urllib3/connection.py:266: SubjectAltNameWarning: Certificate for nucleo.neatocloud.com has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.)
  SubjectAltNameWarning
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/account.py", line 64, in robots
    self.refresh_robots()
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/account.py", line 108, in refresh_robots
    traits=robot['traits']))
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 37, in __init__
    if self.service_version not in SUPPORTED_SERVICES:
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 150, in service_version
    return self.available_services['houseCleaning']
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 146, in available_services
    return self.state['availableServices']
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 142, in state
    return self.get_robot_state().json()
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 118, in get_robot_state
    return self._message({'reqId': "1", 'cmd': "getRobotState"})
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 55, in _message
    headers=self._headers)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 107, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 53, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 454, in request
    prep = self.prepare_request(req)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 388, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/lib/python3/dist-packages/requests/models.py", line 297, in prepare
    self.prepare_auth(auth, url)
  File "/usr/lib/python3/dist-packages/requests/models.py", line 490, in prepare_auth
    r = auth(self)
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 170, in __call__
    signing = hmac.new(key=self.secret.encode('utf8'),
AttributeError: 'NoneType' object has no attribute 'encode'

I have two robots listed at my Neato account.

bphermansson commented 5 years ago

Problem is solved for me now, working as expected.

fermulator commented 5 years ago

There appears to be insufficient information here to explain if/how anything was fixed. As per https://github.com/home-assistant/home-assistant/issues/11968, users with newer Neato Botvacs are experiencing issues with connectivity. Some suspect due to the newer standard of "OPS" prefix in the serial number.

Can we please re-open this ticket? (or is it to be deemed the same as #30)?

fermulator commented 5 years ago

Just confirmed (pip3 latest pybotvac), same issue still:

>>> for robot in Account('foo@email.com', '(SNIPPED_PASSWORD)').robots: print(robot)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/account.py", line 63, in robots
    self.refresh_robots()
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/account.py", line 109, in refresh_robots
    endpoint=robot['nucleo_url']))
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 41, in __init__
    if self.service_version not in SUPPORTED_SERVICES:
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 213, in service_version
    return self.available_services['houseCleaning']
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 209, in available_services
    return self.state['availableServices']
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 205, in state
    return self.get_robot_state().json()
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 163, in get_robot_state
    return self._message({'reqId': "1", 'cmd': "getRobotState"})
  File "/usr/local/lib/python3.5/dist-packages/pybotvac/robot.py", line 60, in _message
    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: 404 Client Error: Not Found for url: https://nucleo.neatocloud.com/vendors/neato/robots/OPS#####-B#A#AAB#B##B/messages

My bot is fully functional, on the WiFi, powered on, etc. (works fully from NeatoApp directly)

fermulator commented 5 years ago

Perhaps this issue was confounded. The merge implies the fix was to ignore robots not connected/online. OK. But in #30, this may describe another problem, which I am experiencing.

fermulator commented 5 years ago

@bphermansson , please confirm if issue is still present for you? (the re-open may not be required now)

The above snippet you provided works for me

Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux

>>> from pybotvac import Account
>>> for robot in Account('<SNIP>', '<SNIP>').robots: print(robot)
... 
Your 'boyle-ORIGINAL' robot is offline.
Name: boyle, Serial: (SNIP) Traits: ['maps']
Help on package pybotvac:

NAME
    pybotvac

PACKAGE CONTENTS
    account
    robot
    version

VERSION
    0.0.13

FILE
    /home/fermulator/projects/pybotvac/pybotvac/__init__.py
fermulator commented 5 years ago

@stianaske , let's close

Santobert commented 3 years ago

It seems that this problem occurs when the robots are not fully set up at Neato. There are situations where a robot was set up twice and the old robot was responsible for these errors. In other situations, an old robot that was not actively being used caused these errors.

Unfortunately, this trick with the Mac address doesn't always work, because fully functional robots sometimes lack the Mac address. The Mac address is also not documented, so we should not rely on it.

In https://github.com/stianaske/pybotvac/pull/59 I had to remove that check in order to prevent false positives. Since then, there are some issues popping up again. See:

Even though I see no obvious way to solve this issue we can work around it. #68 is the first step in this direction as we skip invalid robots (those without a secret in this case) for now.