Issue storing file results after successfully running automation

Hi @jonathon,

Have worked a bit on trying to get Speckle Automate to work. Was actually able to get it running in more or less a day, so cheers for all the nice work so far, making it relatively easy to start.

I’m trying to run a basic test case, where I post-process some Speckle data using our own API, create an HTML table based on it, which I then want to store as a file result. At that point, the automation runs into an error. I’ve ran my automation without storing the file result, which then finishes successfully. See here the relevant code:

            # Create a dataframe from the API response
            building_data_df = pd.DataFrame(response['building_data'])

            # Convert to HTML
            building_data_html = building_data_df.to_html()

            # Store as HTML
            with open("./building_data.html", "w") as fp:
                fp.write(building_data_html)

            # Mark run as successful
            automate_context.mark_run_success("Building data table successfully generated!")

            # ERROR OCCURRING HERE!
            # Attach the HTML table to the Speckle model
            automate_context.store_file_result("./building_data.html")

See here the error I’m running into, it’s not finding a specific API endpoint when targeting the blob storage it seems:

To me, this seems like something that’s out of my hands, so therefore this forum post.
Also pleased to hear if either the path isn’t correctly set, or if storing HTML files has caveats.

Thanks in advance!

1 Like

I will cross check with other functions i know to be working, but in the meantime from memory, lets try a couple of things:

import tempfile

temp_dir = tempfile.gettempdir()
temp_file = Path(
    temp_dir, f"building_data_{datetime.now().timestamp():.0f}.html"
)

try:
    with open(temp_file, "w") as fp:
        fp.write(building_data_html)
except IOError as e:
    automate_context.mark_run_failure(
        f"Failed to write HTML file: {e}"
    )
    raise

try:
    if temp_file.exists():
        automate_context.store_file_result(str(temp_file))
    else:
        raise FileNotFoundError(f"File not found: {temp_file}")
except Exception as e:
    automate_context.mark_run_failure(
        f"Failed to store file result: {e}"
    )
    raise
  • Create Temporary File Path:
    • Generates a unique temporary file path with a timestamp.
  • Write HTML to File:
    • Saves HTML content to the temporary file.
    • Prints a success message or marks the run as failed on IOError.
  • Store File Result:
    • Checks if the file exists and passes the path to store_file_result.
    • Prints a success message or raises FileNotFoundError if the file is missing.
    • Handles exceptions by marking the run as failed.
1 Like

Thanks for you quick response @jonathon!
I’ll give this a try today and inform you on the result.

1 Like

@jonathon,

It gives me the exact same error as described initially, so updating the file handling as proposed doesn’t solve the issue. Hope you have some more luck in running the checks : )

ok thats weird - thanks for testing - ill report back asap

Apologies, @Rob, I have been checking in today. I can completely replicate this, and it would appear the SDK is not correctly calling the endpoint. If I find out more I’ll post a workaround, if not I have to pass it to the platform team.

Thanks for checking it out, at least good to hear it can be replicated.
Indeed let me know once a workaround or fix is in!

Good news bad news - my replication function run now works. Maybe give it another go?

1 Like

Nope, doesn’t work yet. But just noticed a new version of specklepy (2.19.6) is available on Github, which should solve this issue, see below PR. Already noticed this double slash in the API endpoint it targets.

fix(automate): remove extra slash by cdriesler · Pull Request #346 · specklesystems/specklepy (github.com)

The 2.19.6 version is not available on PyPi yet, so I tried to directly include it in my project through a direct reference to Github, but this fails during building and deploying the function on Github. So I guess I’ll just anxiously wait for it to be released on pypi. Guess @gjedlicska is involved in that? :sweat_smile:

1 Like

The release got stuck in the pipeline, now it should be out @Rob

2 Likes

Perfect, now works like a charm, great functionality!

4 Likes