AstroHuntsman / huntsman-pocs

POCS on the Huntsman Telescope
MIT License
7 stars 8 forks source link

Source of the "ValueError: too many values to unpack (expected 2)" error #604

Open fergusL opened 10 months ago

fergusL commented 10 months ago

This error keeps popping up sporadically and I have confirmed that is a resulting from some form of error from TheSkyX and a parsing error in panoptes.pocs.utils.theskyx. What is going on is as follows:

pocs issues a command via TheSkyX which fails in some way and returns a response

In [4]: pocs.observatory.dome.unpark()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[4], line 1
----> 1 pocs.observatory.dome.unpark()

File /opt/conda/lib/python3.10/site-packages/huntsman/pocs/dome/musca.py:266, in HuntsmanDome.unpark(self, timeout)
    264 while not timer.expired():
    265     try:
--> 266         response = self.read()
    267     except TheSkyXTimeout:
    268         continue

File /opt/conda/lib/python3.10/site-packages/panoptes/pocs/dome/bisque.py:156, in Dome.read(self, timeout)
    154 def read(self, timeout=5):
    155     while True:
--> 156         response = self.theskyx.read()
    157         if response is not None or timeout == 0:
    158             break

File /opt/conda/lib/python3.10/site-packages/panoptes/pocs/utils/theskyx.py:62, in TheSkyX.read(self, timeout)
     59     response, err = response.split('|')
     61 if 'Error:' in response:
---> 62     response, err = response.split(':')
     64 if err is not None and 'No error' not in err:
     65     if 'Error = 303' in err:

ValueError: too many values to unpack (expected 2)

If we capture the response object returned from TheSkyX we can see what is going wrong:

In [13]: dome.write(dome._get_command('dome/unpark.js'))

In [14]: response = dome.theskyx.socket.recv(2048).decode()

In [15]: response
Out[15]: 'TypeError: Error: command failed. Error = 206.|No error. Error = 0.'

In [16]: response, err = response.split('|')

In [17]: response
Out[17]: 'TypeError: Error: command failed. Error = 206.'

In [18]: response, err = response.split(':')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[18], line 1
----> 1 response, err = response.split(':')

ValueError: too many values to unpack (expected 2)

So the panoptes.pocs.utils.theskyx.read() assumes there will only ever be one ":" character in the response string, so when it splits on this response it creates three strings instead of two.

This presents a bit of annoying problem as we have frozen ours pocs version so we can't just submit a PR to POCS....