zacs / ha-nfl

NFL game scores custom component for Home Assistant
42 stars 32 forks source link

Error fetching NFL data: module 'arrow' has no attribute 'FORMAT_W3C' #23

Closed K-Money closed 1 year ago

K-Money commented 1 year ago

This error originated from a custom integration.

Logger: custom_components.nfl Source: helpers/update_coordinator.py:182 Integration: NFL (documentation, issues) First occurred: 8:10:58 PM (1 occurrences) Last logged: 8:10:58 PM

Error fetching NFL data: module 'arrow' has no attribute 'FORMAT_W3C'

Home Assistant 2022.9.4 Supervisor 2022.08.6 Operating System 9.0 Frontend 20220907.2 - latest

zacs commented 1 year ago

This is weird. I just checked and arrow has not deprecated the FORMAT_W3C function at all.

Have you installed any new custom components lately? Maybe something that would keep arrow snapped to an old version that doesn't include FORMAT_W3C. Far fetched since it would need to be years old.

Did the component work before? If so, did it stop working randomly, or after an upgrade or installing something else?

K-Money commented 1 year ago

I haven't installed any other components lately but this was my first time trying to install this nfl component. I tried searching the logs for a deeper stack trace but couldn't find anything beyond what I posted. Is there a way to tell what other components are using dependencies?

K-Money commented 1 year ago

I thought I'd try to manually install arrow to see if that could jimmy something loose. Not sure if I was successful, but even after a restart it didn't change anything and still gives the same error. Screenshot of console

zacs commented 1 year ago

Can you get into a Python prompt in the image and run this: print(arrow.now().format(arrow.FORMAT_W3C))

I suspect it will fail, although it should not!

K-Money commented 1 year ago

It looks like it works properly within python to give the date, but python is only accessible if I specifically use python3. Could that be related? Screenshot

Also, since I'm using HassOS and it makes it challenging to get access to the base level of the linux OS, I'm using this add-on for the commands being shown in case there's some environment shenanigans at play.

zacs commented 1 year ago

Hmmm yah I can't imagine why it would throw the error when typing it into the console work perfectly fine. It looks like that addon logs you in as root, and I'm sure HA runs as a different user. I wonder if you could add a terminal template function to check the output of the command...

Can you make a sensor like this:

sensor:
  - platform: command_line
    command: python3 -c "import arrow; print(arrow.now().format(arrow.FORMAT_W3C))"
    name: Arrow test

and see if it works?

K-Money commented 1 year ago

Created the sensor and it looks like the command does fail with a nonzero return value, but the return value of 1 doesn't seem super helpful.

Logger: homeassistant.components.command_line Source: components/command_line/init.py:48 Integration: command_line (documentation, issues) First occurred: 12:04:14 AM (1 occurrences) Last logged: 12:04:14 AM Command failed (with return code 1): python3 -c "import arrow; print(arrow.now().format(arrow.FORMAT_W3C))"

Also just to make sure to run a control test, I copied the same command string python3 -c ...etc into the ssh & terminal addon and it does execute correctly with the date/time as the output.

Also, for what it's worth, I took a stab at seeing if I could get any info on what user HA might be running as and this is what I found. I'm guessing it's the hassio user, but not sure if any of the other info shown here is helpful.

zacs commented 1 year ago

Bummer. The only two options I can think of are to get in as the hassio user and do a pip install arrow because the library clearly didn't install. Alternatively you could remove the customer component, reboot, reinstall customer component, then reboot again. I'd hope it would install the dependency in this case.

K-Money commented 1 year ago

Success! Documenting for posterity.

I found that HassOS is actually running everything as root, so root is the right user to be under. Installing it under one of the other users didn't help.

I tried modifying the manifest.json file to force a specific version of arrow. No dice. I tried to force reinstall arrow with --force-reinstall and a particular version. No dice.

Using the info I found here in the custom requirements section. I ran pip install arrow --target /config/depsand then did a restart. That seemed to do the trick. It looks like the default pip install just puts it somewhere that Homeassistant wasn't looking for it.

No idea why the manifest requirement didn't do that itself, but that's for smarter folks than I to ponder.

I've rebooted a few times now and it seems that it's persistent. The arrow_test command_line sensor also works now as well.

Thanks for all the help troubleshooting this and for the component in the first place!