jeffreydwalter / arlo

Python module for interacting with Netgear's Arlo camera system.
Apache License 2.0
517 stars 124 forks source link

Unable to download a snapshot using MFA #173

Closed sfederman closed 3 years ago

sfederman commented 3 years ago

Hi,

I believe I properly set up MFA, and am having the below issue. I had this issue on an existing system, but for testing, I set up a fresh VM. My Installation method is below.

I'd love any help with troubleshooting, and can provide more info if necessary. Thank you in advance for any assistance!

-Scot

What version of Python are you using (python -V)?

Python 3.8.8

What operating system and processor architecture are you using (python -c 'import platform; print(platform.uname());')?

uname_result(system='Linux', node='testserver1', release='5.4.0-80-generic', version='#90-Ubuntu SMP Fri Jul 9 22:49:44 UTC 2021', machine='x86_64', processor='x86_64')

Which Python packages do you have installed (run the pip freeze or pip3 freeze command and paste output)?

arlo @ git+https://github.com/jeffreydwalter/arlo@caff90abbaafcbb34ba447476a27029f2148f5a8
cachetools==4.2.2
certifi==2021.5.30
charset-normalizer==2.0.3
google-api-core==1.31.1
google-api-python-client==2.15.0
google-auth==1.34.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.4.4
googleapis-common-protos==1.53.0
httplib2==0.19.1
idna==3.2
monotonic==1.6
oauthlib==3.1.1
packaging==21.0
pickle-mixin==1.0.2
protobuf==3.17.3
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyparsing==2.4.7
PySocks==1.7.1
pytz==2021.1
requests==2.26.0
requests-oauthlib==1.3.0
rsa==4.7.2
six==1.16.0
sseclient==0.0.22
uritemplate==3.0.1
urllib3==1.24

Which version of ffmpeg are you using (ffmpeg -version)?

ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100

Which Arlo hardware do you have (camera types - [Arlo, Pro, Q, etc.], basestation model, etc.)?

2 x Arlo Pro H3,

What did you do?

Installation

conda create -n "arlo" python=3.8.8
conda activate arlo

conda install pip
pip install git+https://github.com/jeffreydwalter/arlo@mfa-pr

Then followed instructions at: https://github.com/jeffreydwalter/arlo/blob/mfa-pr/docs/ARLO_MFA.md to set up MFA, which seems to be functioning properly (as best as I can tell).

arlo_test.py

from arlo import Arlo

USERNAME = '<actual username here>'
PASSWORD = '<actual password here>'
CREDENTIALS = '/home/sfederman/arlo/arlo/gmail.credentials'

try:
    arlo = Arlo(USERNAME, PASSWORD, CREDENTIALS)
    basestations = arlo.GetDevices('basestation')
    cameras = arlo.GetDevices('camera')
    snapshot_url = arlo.TriggerFullFrameSnapshot(basestations[0], cameras[0])
    arlo.DownloadSnapshot(snapshot_url, 'snapshot.jpg')

except Exception as e:
    print(e)

What did you expect to see?

1. New Email with one time code (it did in fact arrive to the proper Email address)
2. Creation of 'snapshot.jpg' file (this did not occur)

What did you see instead?

(arlo) sfederman@testserver1:~/arlo$ python3 arlo_test.py
Failed to start eventstream thread: can only concatenate str (not "bytes") to str
Exception ignored in: <function EventStream.__del__ at 0x7f39385b8790>
Traceback (most recent call last):
  File "/home/sfederman/anaconda3/envs/arlo/lib/python3.8/site-packages/eventstream.py", line 42, in __del__
  File "/home/sfederman/anaconda3/envs/arlo/lib/python3.8/site-packages/eventstream.py", line 90, in Disconnect
  File "/home/sfederman/anaconda3/envs/arlo/lib/python3.8/site-packages/eventstream.py", line 110, in Unregister
AttributeError: 'EventStream' object has no attribute 'event_stream_thread'

Does this issue reproduce with the latest release?

Yes

jeffreydwalter commented 3 years ago

Just pushed a small fix to the mfa branch. git pull and let me know how it goes.

sfederman commented 3 years ago

Thank you - I just checked it out after updating, and look to be having the same issue:


(arlo) sfederman@testserver1:~/arlo$ python3 arlo_test.py
Failed to start eventstream thread: can only concatenate str (not "bytes") to str
Exception ignored in: <function EventStream.__del__ at 0x7f089ec21790>
Traceback (most recent call last):
  File "/home/sfederman/anaconda3/envs/arlo/lib/python3.8/site-packages/eventstream.py", line 42, in __del__
  File "/home/sfederman/anaconda3/envs/arlo/lib/python3.8/site-packages/eventstream.py", line 90, in Disconnect
  File "/home/sfederman/anaconda3/envs/arlo/lib/python3.8/site-packages/eventstream.py", line 110, in Unregister
AttributeError: 'EventStream' object has no attribute 'event_stream_thread'

(arlo) sfederman@testserver1:~/arlo$ head /home/sfederman/anaconda3/envs/arlo/lib/python3.8/site-packages/eventstream.py -n75 | tail -n1
            event_stream = sseclient.SSEClient('https://myapi.arlo.com/hmsweb/client/subscribe?token='+self.arlo.request.session.headers.get('Authorization'), session=self.arlo.request.session)```
jeffreydwalter commented 3 years ago

I unfortunately don't have any working Arlo cameras to debug this with. Would you be willing to help debug this further?

jeffreydwalter commented 3 years ago

@sfederman I just pushed another small change. Let me know if it made a difference.

sfederman commented 3 years ago

I'm more than happy to help debug to the extent I can!

sfederman commented 3 years ago

Oh - and I do see the most recent change, but it is in the master branch - I've been using the mfa-pr branch, as I need to use MFA from now on...

sfederman commented 3 years ago

Not sure if this is helpful, but I tried the below change, which I thought might be the change intended in eventstream.py (the commented out line was changed to the line immediately following it):

   def Start(self):
        try:
            #event_stream = sseclient.SSEClient('https://myapi.arlo.com/hmsweb/client/subscribe?token='+self.arlo.request.session.headers.get('Authorization'), session=self.arlo.request.session)
            event_stream = sseclient.SSEClient('https://myapi.arlo.com/hmsweb/client/subscribe', session=self.arlo.request.session)
            self.event_stream_thread = threading.Thread(name="EventStream", target=self.event_handler, args=(self.arlo, event_stream, self.event_stream_stop_event, ))
            self.event_stream_thread.setDaemon(True)
            self.event_stream_thread.start()
        except Exception as e:
            raise Exception('Failed to start eventstream thread: {0}'.format(e))

When I tried this, here is the result:

(arlo) sfederman@testserver1:~/arlo$ python3 arlo_test.py
'Arlo' object has no attribute 'user_id'
jeffreydwalter commented 3 years ago

@sfederman just pushed what I believe to be a fix. Please give it a whirl! Thanks!

sfederman commented 3 years ago

Thanks so much - that appears to be working. Snapshots are functional, which is all I need for now. I'll do some more testing with the API, and see if any issues remain.

Thanks again for your assistance, I appreciate your help, and the creation of the repository.

sfederman commented 3 years ago

To be clear, I have a combination of the changes across the 2 branches right now. Below is what is working:

arlo.py (line 208)

        self.user_id = auth_body['data']['userId']

eventstream.py

    def Start(self):
        try:
            header_auth = self.arlo.request.session.headers.get('Authorization')
            decoded_header = header_auth.decode()
            event_stream = sseclient.SSEClient('https://myapi.arlo.com/hmsweb/client/subscribe?token='+decoded_header, session=self.arlo.request.session)
            self.event_stream_thread = threading.Thread(name="EventStream", target=self.event_handler, args=(self.arlo, event_stream, self.event_stream_stop_event, ))
            self.event_stream_thread.setDaemon(True)
            self.event_stream_thread.start()
        except Exception as e:
            raise Exception('Failed to start eventstream thread: {0}'.format(e))
        return self
jeffreydwalter commented 3 years ago

Does it work with what's in the mfa branch?

On Mon, Aug 2, 2021, 11:11 PM Scot Federman @.***> wrote:

To be clear, I have a combination of the changes across the 2 branches right now. Below is what is working:

arlo.py (line 208)

    self.user_id = auth_body['data']['userId']

eventstream.py

def Start(self):
    try:
        header_auth = self.arlo.request.session.headers.get('Authorization')
        decoded_header = header_auth.decode()
        event_stream = sseclient.SSEClient('https://myapi.arlo.com/hmsweb/client/subscribe?token='+decoded_header, session=self.arlo.request.session)
        self.event_stream_thread = threading.Thread(name="EventStream", target=self.event_handler, args=(self.arlo, event_stream, self.event_stream_stop_event, ))
        self.event_stream_thread.setDaemon(True)
        self.event_stream_thread.start()
    except Exception as e:
        raise Exception('Failed to start eventstream thread: {0}'.format(e))
    return self

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jeffreydwalter/arlo/issues/173#issuecomment-891506662, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEKOBZEFAWMPQ5RJO6ZC7DT25T5LANCNFSM5BFKKH4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

sfederman commented 3 years ago

No, not as is. I'll try to narrow down why...

jeffreydwalter commented 3 years ago

Ok, I see you're doing header_auth.decode(). I just pushed a commit that does the same. Let me know how it goes!

sfederman commented 3 years ago

It seems to function properly now! I rebuilt a conda environment with the code, and ran the same test as in the original issue arlo_test.py, and did get an image downloaded.

jeffreydwalter commented 3 years ago

Thanks again for your help in debugging this.