Repository: fronzbot/blinkpy

Issue:
Video download problem - "Unauthorized Access","code":101
I have been using Blinkpy to download videos to my PC for almost a year. Last time that I was able to download the video files was about 4 weeks ago. Today when I was trying to download new video files since my last downloading, I found the sizes of the downloaded video files are all 1kB, obviously something was not right. When I open the video files they just have one line of ASCII text showing below:
{"message":"Unauthorized Access","code":101}
My user name and password should be correct because after the code:
>blink.auth = auth
>blink.start()
No error message is shown. If the password is not correct, the error message 'Login endpoint failed. Try again later.' will be shown. 

Anybody know what is the csuse of this problem? Thank you.



Discussion:

Patch:
diff --git a/blinkpy/auth.py b/blinkpy/auth.py
index bc61387..c7e997b 100644
--- a/blinkpy/auth.py
+++ b/blinkpy/auth.py
@@ -58,7 +58,11 @@ class Auth:
         """Return authorization header."""
         if self.token is None:
             return None
-        return {"TOKEN_AUTH": self.token, "user-agent": DEFAULT_USER_AGENT}
+        return {
+            "TOKEN_AUTH": self.token,
+            "user-agent": DEFAULT_USER_AGENT,
+            "content-type": "application/json",
+        }
 
     def create_session(self, opts=None):
         """Create a session for blink communication."""
@@ -227,6 +231,9 @@ class Auth:
             try:
                 json_resp = response.json()
                 blink.available = json_resp["valid"]
+                if not json_resp["valid"]:
+                    _LOGGER.error(f"{json_resp['message']}")
+                    return False
             except (KeyError, TypeError):
                 _LOGGER.error("Did not receive valid response from server.")
                 return False


Test patch:
diff --git a/tests/test_auth.py b/tests/test_auth.py
index c5c082b..45e6cff 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -128,7 +128,11 @@ class TestAuth(unittest.TestCase):
     def test_header(self):
         """Test header data."""
         self.auth.token = "bar"
-        expected_header = {"TOKEN_AUTH": "bar", "user-agent": const.DEFAULT_USER_AGENT}
+        expected_header = {
+            "TOKEN_AUTH": "bar",
+            "user-agent": const.DEFAULT_USER_AGENT,
+            "content-type": "application/json",
+        }
         self.assertDictEqual(self.auth.header, expected_header)
 
     def test_header_no_token(self):