How to catch error info of rclone rc core/stats?

What is the problem you are having with rclone?

I am running rclone copy --rc. At same time I am running a for-loop to run rclone rc core/stats. But I want to break the for-loop of rclone rc core/stats when the task of rclone copy --rc is ended (killed or done).

There is such information printed after rclone copy --rc is ended,
Failed to rc: connection failed: Post http://localhost:5572/core/stats: dial tcp [::1]:5572: connect: connection refused

But I do not know how to catch this information?

cnt_error  = 0
while True:
    cmd = 'rclone rc core/stats'
        response = subprocess.check_output(cmd, shell=True)
        cnt_error = 0
    except subprocess.CalledProcessError as error:
        cnt_error = cnt_error + 1

    if cnt_error >= 3:
        print('3 times over')

What is your rclone version (output from rclone version)

rclone v1.49.0-016-gf97a3e85-beta

  • os/arch: linux/amd64
  • go version: go1.12.9

Which OS you are using and how many bits (eg Windows 7, 64 bit)

Ubuntu 16.04

Which cloud storage system are you using? (eg Google Drive)

Google Drive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone copy --rc gd1: gd2:

You can check the exit code by catching subprocess.CalledProcessError and checking the returncode attribute on the error.

But the try and except cannot catch that subprocess.CalledProcessError at all. Because the for-loop is never stopped even though the cmd rclone copy --rc is ended. So I come here asking for some help.

Many thanks for this warm forum.

Are you sure its never caught?

The logic looks wrong to me. There shouldn't be a continue at all in the except clause, otherwise it will never go to the check part of 3 errors.

really thx. It should be (use SubprocessError rather than CalledProcessError and at same time delete the row of continue):

cnt_error = 0
cnt_403_retry = 0
size_GB_done_before = 0
while True:
    cmd = 'rclone rc core/stats'
        response = subprocess.check_output(cmd, shell=True)
        cnt_error = 0
    except subprocess.SubprocessError as error:
        # continually ...
        cnt_error = cnt_error + 1

    if cnt_error >= 3:
        print('3 times over')

thx @ncw. It should be subprocess.SubprocessError

SubprocessError will catch all related errors from subprocess (eg timeout), whereas CalledProcessError is a specialized version of that which will only catch error exit codes from the process and other errors should bubble up.

>>> subprocess.check_output(["false"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/", line 395, in check_output
  File "/usr/lib/python3.7/", line 487, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['false']' returned non-zero exit status 1.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.