fronzbot / blinkpy

A Python library for the Blink Camera system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception on sync module refresh call

swerb73 opened this issue · comments

I'm running the latest 0.17 branch and seem to be having a lot of new exceptions when I call a refresh of the sync module, example (copying full Traceback on the last call):
2021-03-02 06:38:30,879 ERROR flaskapp Thread-94 : Exception on /blink_enable_pool [GET]
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python38\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Python38\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Python38\lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Python38\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Python38\lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "c:\Blinkpy\flaskapp.py", line 150, in run_blink_enable_pool
blink.refresh(force_cache=True)
File "C:\Python38\lib\site-packages\blinkpy\helpers\util.py", line 144, in wrapper
result = method(*args, *kwargs)
File "C:\Python38\lib\site-packages\blinkpy\blinkpy.py", line 93, in refresh
sync_module.refresh(force_cache=(force or force_cache))
AttributeError: 'bool' object has no attribute 'refresh'

Once I'm in this loop it seems to constantly error on any call I make to refresh:
blink.refresh(force_cache=True)

Anything change in 0.17 that could cause this?

I don't think so. It looks like maybe something in your code is setting the sync_module variable to a boolean. Like you're assigning it the output of some method and the method returns True or False.

If it's in the library, it would be overwriting the class to a bool and I'm not sure where that could even happen but I'll dig in and see if anything pops up

Here's a diff between 0.17.1 and 0.16.4: diff

OK, odd, the implementation I've been using hasn't changed but I wonder if I've thrown things off by trying to get the mini's fully working and that's causing other issues throughout? Question, is there a way to check if a camera is a mini in code to use the sync module call vs. camera call to set motion detection or arm it?

Question, is there a way to check if a camera is a mini in code to use the sync module call vs. camera call to set motion detection or arm it?

Yes, you can call BlinkCamera.camera_type to get that info

Wow, I seemed to have a fully screwed up integration now, how odd. But I confirmed that anytime I call blink.refresh or a sync module only refresh I get this:
File "c:\Blinkpy\flaskapp.py", line 138, in run_blink_disable_pool
blink.refresh(force_cache=True)
File "C:\Python38\lib\site-packages\blinkpy\helpers\util.py", line 144, in wrapper
result = method(*args, *kwargs)
File "C:\Python38\lib\site-packages\blinkpy\blinkpy.py", line 93, in refresh
sync_module.refresh(force_cache=(force or force_cache))
AttributeError: 'bool' object has no attribute 'refresh'

Yes, ok, just wrote a quick script that only initializes blink then tries to do a refresh and I get this error regardless if I call it with no force/force_cache, or if I do:

2021-03-02 16:43:16,205 ERROR flaskapp Thread-100 : Exception on /blink_refresh [GET]
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python38\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Python38\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Python38\lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Python38\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Python38\lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "c:\Blinkpy\flaskapp.py", line 72, in run_blink_refresh
blink.refresh()
File "C:\Python38\lib\site-packages\blinkpy\helpers\util.py", line 144, in wrapper
result = method(*args, *kwargs)
File "C:\Python38\lib\site-packages\blinkpy\blinkpy.py", line 93, in refresh
sync_module.refresh(force_cache=(force or force_cache))
AttributeError: 'bool' object has no attribute 'refresh'

Can you post your script? I'll see if I can replicate

Well crap, I ripped out all my flask stuff and just ran a startup/refresh and it worked fine. Sorry for the false alarm here but I think it must be something else...

Any ideas to point me in the right direction, seems like "blink" is being reassigned to a boolean somewhere along the way vs. the blink library object when I initialize?

And it's odd, any other calls I make to blink. seem to work, for example right before this I have a:
blink.cameras["NAME"].arm = False and that works fine...

OK, I've been trying to figure this out now the past week and have simplified my code as much as I can as being part of a Flask application, and I can't figure out why I continue to get this exception:

File "c:\Blinkpy\flaskapp.py", line 72, in run_blink_refresh
return 'blink_refresh'
File "C:\Python38\lib\site-packages\blinkpy\helpers\util.py", line 144, in wrapper
result = method(*args, *kwargs)
File "C:\Python38\lib\site-packages\blinkpy\blinkpy.py", line 93, in refresh
sync_module.refresh(force_cache=(force or force_cache))
AttributeError: 'bool' object has no attribute 'refresh'

If I call the app rule for '/' it works, but if I call /blink_refresh I get the error.

Here's the code:

`
from flask import Flask, request, jsonify
import os, subprocess
import logging
import time
import ftplib
import shutil

import datetime

app = Flask(name)
#logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')
logging.basicConfig(filename='BlinkAccess.log', level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')

now = datetime.datetime.now()
dt_string = now.strftime("%m/%d/%Y %H:%M:%S")

app.logger.info('Before Blink Init')

from blinkpy.blinkpy import Blink
from blinkpy.auth import Auth
from blinkpy.helpers.util import json_load

blink = Blink()
auth = Auth(json_load("c:\Blinkpy\cred.json"), no_prompt=True)
blink.auth = auth

opts = {"retries": 5, "backoff": 2}
blink.auth.session = blink.auth.create_session(opts=opts)

try:
blink.start()
blink.setup_post_verify()
blink.save("C:\Blinkpy\cred.json")
except TypeError:
app.logger.error('Exception %s', blink.auth.login())

app.logger.info('After Blink Init')

sleeptime = 15

@app.route('/')
def homepage():
return 'Hello, World! - Flask Homepage'

@app.route('/blink', methods=['GET'])
def run_blink_python():
if 'script' in request.args:
cmd = 'python.exe ' + request.args['script']
callresult = subprocess.call(cmd, shell=True)
return cmd + ', RESULT: ' + str(callresult)

@app.route('/blink_refresh', methods=['GET'])
def run_blink_refresh():
blink.refresh()
time.sleep(sleeptime)
return 'blink_refresh'

if name == 'main':
logger = logging.getLogger('werkzeug')
handler = logging.FileHandler('FlaskAccess.log')
logger.addHandler(handler)
app.logger.addHandler(handler)
app.run(host='0.0.0.0', port=5000, threaded=True, debug=True)
`

OK, I wonder if this is somehow related to intermingling normal sync modules and mini's on the same configuration? I have 5 normal sync modules, one of the sync modules has a mini, then I have a location that has no sync module's, just mini's.

This all seemed to start happening when I went down this path?

It could be. I don't know where in the library that could happen, though, so I'm a bit perplexed

OK, let me know if you can think of ways to troubleshoot this, happy to help. it's really odd behavior, when I enable/disable a normal wireless camera I always get the error now. Guessing the code/library does a refresh after enabling/disabling motion on a camera?

Guessing the code/library does a refresh after enabling/disabling motion on a camera?

No it does not. Is that the only time you get the error? It might be worth removing flask and doing all this stuff manually to debug. Eliminate that variable because a refresh after enabling/disabling motion should not call refresh unless it's manually scripted.

It is odd, I pulled all refreshes from the code and only call arm/disarm now, but still get the error. I'll triple check the code this morning...

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within seven days. Thank you for your contributions.

commented

This issue is now being closed due to inactivity.