tchellomello / python-ring-doorbell

Python Ring Door Bell is a library written in Python 3 that exposes the Ring.com devices as Python objects.
GNU Lesser General Public License v3.0
538 stars 171 forks source link

Cannot download ring videos #350

Open SergiuCip opened 4 months ago

SergiuCip commented 4 months ago

When trying to download a video i get the following error: Got error: RingError('HTTP error with status code 404 during query of url https://api.ring.com/clients_api/dings/

Please help

sdb9696 commented 4 months ago

Can you provide a bit more information. How are you trying to download it? Do other queries work? Maybe post some logs etc?

SergiuCip commented 4 months ago

Sure, So I can run the following commands: ring-doorbell list, ring-doorbell motion-detection --device-name "DEVICENAME" --on, ring-doorbell history --device-name "Front Door" but when I try running the following command ring-doorbell videos --download-all command, I get the following error:

❯ ring-doorbell videos --download-all
---------------------------------
Ring CLI
    Getting videos linked on your Ring account.
    This may take some time....

    Downloading 70 videos linked on your Ring account.
    This may take some time....

    1/70 Downloading xxxx.mp4
Got error: RingError('HTTP error with status code 404 during query of url https://api.ring.com/clients_api/dings/xxxx/recording: 404 Client Error: Not Found for url: https://share-service-download-bucket.s3.amazonaws.com/xxxxx.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=xxxxSignedHeaders=host&X-Amz-Signature=xxxx')

Traceback (most recent call last):
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/ring_doorbell/auth.py", line 163, in query
    resp.raise_for_status()
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://share-service-download-bucket.s3.amazonaws.com/xxxmp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/ring_doorbell/cli.py", line 47, in __call__
    asyncio.run(self.main(*args, **kwargs))
  File "/Users/sergiu/miniforge3/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/sergiu/miniforge3/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/asyncclick/core.py", line 1120, in main
    rv = await self.invoke(ctx)
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/asyncclick/core.py", line 1739, in invoke
    return await _process_result(await sub_ctx.command.invoke(sub_ctx))
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/asyncclick/core.py", line 1485, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/asyncclick/core.py", line 824, in invoke
    rv = await rv
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/asyncclick/core.py", line 824, in invoke
    rv = await rv
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/ring_doorbell/cli.py", line 584, in videos
    device.recording_download(event["id"], filename=filename, override=False)
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/ring_doorbell/doorbot.py", line 387, in recording_download
    req = self._ring.query(url, timeout=timeout)
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/ring_doorbell/ring.py", line 142, in query
    return self._query(url, method, extra_params, data, json, timeout)
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/ring_doorbell/ring.py", line 155, in _query
    response = self.auth.query(
  File "/Users/sergiu/miniforge3/lib/python3.10/site-packages/ring_doorbell/auth.py", line 165, in query
    raise RingError(
ring_doorbell.exceptions.RingError: HTTP error with status code 404 during query of url https://api.ring.com/clients_api/dings/xxxx/recording: 404 Client Error: Not Found for url: https://share-service-download-bucket.s3.amazonaws.com/

unless python3 isn't supported?

5E7EN commented 4 months ago

Encountering the same error now using Python 3.8 (albeit a different endpoint) - yesterday it worked fine:

ring_doorbell.exceptions.RingError: HTTP error with status code 404 during query of url 
https://api.ring.com/clients_api/doorbots/[...]/history: 404 Client Error: Not Found for url: 
https://api.ring.com/clients_api/doorbots/[...]/history?limit=50&older_than=[...]

This is thrown when invoking the recording_download() function only, in my case. Other functions work fine and provide results properly, like update_data() and devices().

Related #242

chrisnicholls commented 2 months ago

I have noticed the same thing using the cli ring-doorbell videos --download

By manually clicking on the link after getting the 404, I realized that it works, and if i re-run the same cli command, the first video then downloads and the 2nd fails, and this can be repeated for the rest of the videos.

I believe what's happening is the download process is an async process. It takes a few moments for the file to get exported to the s3 bucket before it is actually available to download.

dakkusingh commented 3 weeks ago

Same issue

dakkusingh commented 3 weeks ago

I believe what's happening is the download process is an async process. It takes a few moments for the file to get exported to the s3 bucket before it is actually available to download.

I have noticed the same thing using the cli ring-doorbell videos --download

By manually clicking on the link after getting the 404, I realized that it works, and if i re-run the same cli command, the first video then downloads and the 2nd fails, and this can be repeated for the rest of the videos.

I believe what's happening is the download process is an async process. It takes a few moments for the file to get exported to the s3 bucket before it is actually available to download.

Its actually nothing to do with AWS record / save time.

if you try to download older videos by manually specifying the event ID, you would run into same issue.

example

devices = ring.video_devices()

event_ids = [1234, 5678]

for eid in event_ids:
    devices[0].recording_download(eid, filename)
5E7EN commented 3 weeks ago

That's not a contradiction to what I said. The ring server still needs to process the (albeit old) video file to S3 for sharing.

On Tue, Jun 11, 2024, 9:27 PM Dakku @.***> wrote:

I believe what's happening is the download process is an async process. It takes a few moments for the file to get exported to the s3 bucket before it is actually available to download.

I have noticed the same thing using the cli ring-doorbell videos --download

By manually clicking on the link after getting the 404, I realized that it works, and if i re-run the same cli command, the first video then downloads and the 2nd fails, and this can be repeated for the rest of the videos.

I believe what's happening is the download process is an async process. It takes a few moments for the file to get exported to the s3 bucket before it is actually available to download.

Its actually nothing to do with AWS record / save time.

if you try to download older videos by manually specifying the event ID, you would run into same issue.

example

devices = ring.video_devices()

event_ids = [1234, 5678]

for eid in event_ids: devices[0].recording_download(eid, filename)

— Reply to this email directly, view it on GitHub https://github.com/tchellomello/python-ring-doorbell/issues/350#issuecomment-2161369120, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH33UMO7O2DG567VNFEKMCDZG46SFAVCNFSM6AAAAABDNHZRYGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRRGM3DSMJSGA . You are receiving this because you commented.Message ID: @.***>

guivernl commented 2 weeks ago

I had the same issue - I solved it by making it wait 20 seconds until it tries the same file again. It usually works after one or 2 retries

    try_again = True
    while try_again:
        try:
            frontdoor.recording_download(id_value, filename=filename, override=True)
            try_again = False
        except RingError as e:
            if '404' in str(e):
                print(f"File for ID {id_value} not found. Wait for 20 seconds and retrying...")
                time.sleep(20)
            else:
                print(f"An error occurred: {e}")
                time.sleep(10)
                try_again = False
dakkusingh commented 2 weeks ago

I tried the time limit and still couldnt get it to work.

I had to roll my own download function using:

video_url = device.recording_url(event["id"])

and you can manually download the unbranded video without times burnt into it!