Skip to content

KeyError: 'content-length' on v1.2.7 #294

Closed

Description

@sjt-rvx

Is there an existing issue for this?

  • I have searched the existing issues and added correct labels.

Description

Current Behavior

When running ayon-python-api v1.2.7 versus a server running 1.13.6+202512171758 and calling
ayon_api.download_file(file_url, destination) I get a KeyError on 'content-length'

src/rvx_syndic/note.py:105: in path
    ayon_api.download_file(
.venv/lib/python3.13/site-packages/ayon_api/_api.py:987: in download_file
    return con.download_file(
.venv/lib/python3.13/site-packages/ayon_api/server_api.py:1489: in download_file
    self.download_file_to_stream(
.venv/lib/python3.13/site-packages/ayon_api/server_api.py:1437: in download_file_to_stream
    self._download_file_to_stream(
.venv/lib/python3.13/site-packages/ayon_api/server_api.py:1381: in _download_file_to_stream
    response.headers["Content-length"]

If I downgrade to 1.2.6 the call is successful.

Steps To Reproduce:

No response

Additional context:

Version

ayon-python-api: 1.2.7
server: 1.13.6+202512171758

What platform were you running when you found the bug?

Linux - Rocky9

Relevant log output:

Activity

  1. assigned and unassigned on Jan 5, 2026
  2. added theissue type on Jan 5, 2026
  3. iLLiCiTiT commented on Jan 5, 2026

    @iLLiCiTiT
    Member

    May I ask what are you downloading (url example)? Did it work with older ayon api or server?

  4. iLLiCiTiT commented on Jan 5, 2026

    @iLLiCiTiT
    Member

    This might resolve the issue, but I can't test it #295 .

  5. sjt-rvx commented on Jan 5, 2026

    @sjt-rvx
    Author

    May I ask what are you downloading (url example)? Did it work with older ayon api or server?

    Yeah, it worked with the api version 1.2.6 (on 1.13.6 server as well)

    it was a note attachment something similar to:

    ayon_api.download_file(f"projects/{self._project_name}/files/{attachment_id}", "/path/to/destination.jpg")

  6. sjt-rvx commented on Jan 5, 2026

    @sjt-rvx
    Author

    I tried running my tests using the pull request revision as my ayon-python-api source in uv. and I think it pulled it in correctly. However I got the same key error. It's weird that this request object does not have content-length in it however it does have these keys

    {'Server': 'openresty', 'Date': 'Mon, 05 Jan 2026 14:38:33 GMT', 'Content-Type': 'text/html; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'cache-control': 'no-cache', 'X-Served-By': 'ayon-dev-url', 'Content-Encoding': 'gzip'}
    
  7. sjt-rvx commented on Jan 5, 2026

    @sjt-rvx
    Author

    Ah, the request is doing something wonky. The contents of the response are:

    '<!DOCTYPE html>\n<html lang="en" data-color-mode="dark">\n  <head>\n          <script type="module" src="/assets/hostInit-CB81M3mg.js"></script>\n        \n    <meta charset="UTF-8" />\n    <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n    <meta name="theme-color" content="#2c313a" />\n    <meta name="description" content="" />\n    <meta name="robots" content="noindex" />\n    <title>AYON</title>\n    <!-- FALLBACK FAVICON -->\n    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">\n    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">\n    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">\n    <link rel="manifest" href="/site.webmanifest">\n    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#00d7a0">\n    <meta name="msapplication-TileColor" content="#00aba9">\n    <!-- FALLBACK FAVICON -->\n    <script type="module" crossorigin src="/assets/index-BoWUAhJM.js"></script>\n    <link rel="stylesheet" crossorigin href="/assets/index-Dsy2eoNX.css">\n  </head>\n  <body>\n    <noscript>You need to enable JavaScript to run this app.</noscript>\n    <div id="root"></div>\n  </body>\n</html>\n'
    

    so it seems the request is failing.

    and the kwargs for the 1.2.7 request (from with get_func(url, **kwargs) as response: fame)

    {'stream': True, 'headers': {'Content-Type': 'application/json', 'x-ayon-platform': 'linux', 'x-ayon-hostname': 'hostname', 'referer': 'http://ayon-dev-url, 'X-Api-Key': '000000apikey0000'}}
    

    however the kwargs for the 1.2.6 request is:

    {'stream': True}
    

    so it's the request itself that's failing

  8. iLLiCiTiT commented on Jan 5, 2026

    @iLLiCiTiT
    Member

    it was a note attachment something similar to:

    Ok, let me try.

  9. iLLiCiTiT commented on Jan 5, 2026

    @iLLiCiTiT
    Member

    Ok, so this is because of fixed bug that was in the download logic. It does not prefill api by default in endpoint. If you pre-pend api/ to the url it should work.

    ayon_api.download_file(
        f"api/projects/{self._project_name}/files/{attachment_id}",
        "/path/to/destination.jpg"
    )

    EDITED:
    For compatibility with both new and old ayon_api you can use this

    rest_url = ayon_api.get_rest_url()
    f"{rest_url}/projects/{self._project_name}/files/{attachment_id}"
  10. sjt-rvx commented on Jan 6, 2026

    @sjt-rvx
    Author

    Bingo. Works like a charm. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions