Unable to store file result on automation during testing

Hi folks

I have a simple automation that attaches a report file to the version. It works well on the server runtime but if I am running local tests the step where I call automate_context.store_file_result(report) throws an exception.

Wondering if anyone stumbled on this before?

Traceback (most recent call last):
  File "C:\Users\barbosav\AppData\Local\pypoetry\Cache\virtualenvs\speckle-automate-py-zHFqlJ0g-py3.12\Lib\site-packages\speckle_automate\runner.py", line 173, in run_function
    automate_function(automation_context, inputs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Dev\area-sync-report\main.py", line 77, in automate_function
    automate_context.store_file_result(Path("report.csv"))
  File "C:\Users\barbosav\AppData\Local\pypoetry\Cache\virtualenvs\speckle-automate-py-zHFqlJ0g-py3.12\Lib\site-packages\speckle_automate\automation_context.py", line 274, in store_file_result  
    httpx.post(
  File "C:\Users\barbosav\AppData\Local\pypoetry\Cache\virtualenvs\speckle-automate-py-zHFqlJ0g-py3.12\Lib\site-packages\httpx\_api.py", line 304, in post
    return request(
           ^^^^^^^^
  File "C:\Users\barbosav\AppData\Local\pypoetry\Cache\virtualenvs\speckle-automate-py-zHFqlJ0g-py3.12\Lib\site-packages\httpx\_api.py", line 100, in request
    return client.request(
           ^^^^^^^^^^^^^^^
  File "C:\Users\barbosav\AppData\Local\pypoetry\Cache\virtualenvs\speckle-automate-py-zHFqlJ0g-py3.12\Lib\site-packages\httpx\_client.py", line 814, in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\barbosav\AppData\Local\pypoetry\Cache\virtualenvs\speckle-automate-py-zHFqlJ0g-py3.12\Lib\site-packages\httpx\_client.py", line 901, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\barbosav\AppData\Local\pypoetry\Cache\virtualenvs\speckle-automate-py-zHFqlJ0g-py3.12\Lib\site-packages\httpx\_client.py", line 929, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\barbosav\AppData\Local\pypoetry\Cache\virtualenvs\speckle-automate-py-zHFqlJ0g-py3.12\Lib\site-packages\httpx\_client.py", line 966, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\barbosav\AppData\Local\pypoetry\Cache\virtualenvs\speckle-automate-py-zHFqlJ0g-py3.12\Lib\site-packages\httpx\_client.py", line 1002, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\barbosav\AppData\Local\pypoetry\Cache\virtualenvs\speckle-automate-py-zHFqlJ0g-py3.12\Lib\site-packages\httpx\_transports\default.py", line 227, in handle_request
    with map_httpcore_exceptions():
  File "C:\Users\barbosav\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "C:\Users\barbosav\AppData\Local\pypoetry\Cache\virtualenvs\speckle-automate-py-zHFqlJ0g-py3.12\Lib\site-packages\httpx\_transports\default.py", line 83, in map_httpcore_exceptions       
    raise mapped_exc(message) from exc
httpx.ConnectError: [Errno 11001] getaddrinfo failed

Could it be because of how you generate the report, effectively as a blob. Is it actually existing?

I write to /tmp first. and upload from there and haven’t had an issue. i also run pytest with -s flag to capture full stack traces.

That’s what I thought.

I added this check to make sure

# save df to csv file
    with open("report.csv", "w") as file:
        df.to_csv(file)
        file.close()

    # check if file was created
    if not Path("report.csv").exists():
        automate_context.mark_run_failed("Failed to create report.csv file.")
        return

    # attach the file to the project
    automate_context.store_file_result(Path("report.csv"))

    # attach the file to the project
    automate_context.mark_run_success("Rooms collected and report generated.")

Still its throwing on store_file_result. The stack track I sent previously was captured from the -s flag.

Any other ideas?

I discovered that the issue was on the formation of the URL. I put a print on the request being fired by the automate sdk and it looked like this.

I have adjusted my .env file to include the final backslash and it now works.

SPECKLE_SERVER_URL="https://app.speckle.systems/"

2 Likes

Nice - are you fully up to date specklepy wise? Just a random thought as we had some reports (i complained about) failing in the reverse situation and I supposed we we’d plugged that trailing slash trap door/