RPC error

If you want to debug more on your own, you might try using Wireshark to capture the network traffic. The Automation API uses gRPC as the underlying logic2-automation protocol and there are methods to analyze gRPC messages within Wireshark itself.

Just looking at the error message you showed above:

It seems like the gRPC server connection was intermittently failing:

ipv4:127.0.0.1:10430

… according to the status code 14 (UNAVAILABLE), per the gRPC documentation:

The service is currently unavailable. This is most likely a transient condition, which can be corrected by retrying with a backoff. Note that it is not always safe to retry non-idempotent operations.

Are you starting & running Logic.exe locally as a standard process natively on Windows 10 desktop/laptop console, or are doing something more elaborate (e.g., using a virtual machine or container, running remotely, etc.)?

Finally, if the issue is more like a race condition internal to the Saleae Logic 2 software itself vs. some type of local networking issue on the PC, you might be able to work around it by adding some delays between automation API calls: like inserting a time.sleep() call before each capture.command in your script?

Note: the line numbers in the quoted error message don’t appear to line up exactly with the attached saleae_test.py script (as the attached file was only 58 lines):

However, the traceback suggests it might be something between the capture.export_raw_data_csv() and capture.save_capture() API calls? If so, perhaps the ‘export csv’ didn’t completely finish and the gRPC server is still busy when the ‘save capture’ is called – so you could try adding a time.sleep() of a few seconds in between those calls first?

One last clue – there was another post about exporting raw data CSV sometimes failing, which might be related to your issue:

[Edit:]
Looks like Saleae has an example for automating long captures that is similar to your code, in their technical FAQ:

… where they suggest using python threading to reduce latency in between captures. This technique might help, especially if you need to insert a delay between saving the raw CSV and the capture file.

Alternatively, you could temporarily omit saving the raw CSV file and see if saving the capture file only resolves the problem? If so, you can always export the CSV file from the capture files (*.sal) later, rather than exporting it while collecting the data in the first place. For example, you could create a separate script that would use the automation API load_capture() method and export raw data CSV from there?