fronzbot / blinkpy

A Python library for the Blink Camera system
MIT License
525 stars 111 forks source link

_parse_downloaded_items throws AttributeError: module 'aiofiles' has no attribute 'ospath' #919

Closed tsolid closed 2 months ago

tsolid commented 2 months ago

Describe the bug I grabbed the latest DEV build and compiled. When my weekly job to download recent videos ran it threw this error.

File "/XXX/env/lib/python3.9/site-packages/blinkpy/blinkpy.py", line 415, in _parse_downloaded_items
    if await aiofiles.ospath.isfile(filename):
AttributeError: module 'aiofiles' has no attribute 'ospath'

Reviewed the function: https://github.com/fronzbot/blinkpy/blob/dev/blinkpy/blinkpy.py#L415

I had to add the following changes to get it resolved. This could be due to the VENV I am running but thought I would at least log a ticket just in case.

diff --git a/blinkpy/blinkpy.py b/blinkpy/blinkpy.py
index 027e2ff..e46a2c5 100644
--- a/blinkpy/blinkpy.py
+++ b/blinkpy/blinkpy.py
@@ -17,6 +17,7 @@ import time
 import logging
 import datetime
 import aiofiles
+import aiofiles.ospath
 from requests.structures import CaseInsensitiveDict
 from dateutil.parser import parse
 from slugify import slugify

Home Assistant version (if applicable): N/A

blinkpy version (not needed if filling out Home Assistant version): DEV latest

mkmer commented 2 months ago

Or change ospath to aiofiles.ospath. I suppose we missed one?

OR - something strange is going on. Did you edit aiofiles.ospath to ospath after adding the import? We had an issue with the older version of aiofiles not importing aiofiles.ospath -> everything should be in the upper level.

tsolid commented 2 months ago

Here's my PIP list, first thing I tried was a forced reinstall of aiofiles, then did a fresh venv...

(env) XX@YY:~/$ pip list --local
Package            Version
------------------ ----------
aiofiles           23.2.1
aiohttp            3.9.1
aiosignal          1.3.1
astral             3.2
async-timeout      4.0.3
attrs              23.2.0
blinkpy            0.23.0b7
certifi            2023.11.17
charset-normalizer 3.3.2
frozenlist         1.4.1
idna               3.6
multidict          6.0.4
pillow             10.2.0
pip                24.0
python-dateutil    2.8.2
python-slugify     8.0.1
requests           2.31.0
requests-toolbelt  1.0.0
setuptools         58.1.0
six                1.16.0
sortedcontainers   2.4.0
text-unidecode     1.3
urllib3            2.1.0
yarl               1.9.4
mkmer commented 2 months ago

It's VERY odd that aiofiles.ospath is not there, but you can import it. Such fun with libraries :(

mkmer commented 2 months ago

Looks like this isn't an "easy" fix for everyone. They moved these into aiofiles.os OR directly import as you did. Unfortunately, this will fail for older versions of aiofiles.

Thanks for sharing the issue