8000 Privacy plugin crashes on HTTP errors · Issue #8012 · squidfunk/mkdocs-material · GitHub
[go: up one dir, main page]

Skip to content

Privacy plugin crashes on HTTP errors #8012

@Lucas-C

Description

@Lucas-C

Context

I am the maintainer of fpdf2 and use your excellent theme for our documentation: https://py-pdf.github.io/fpdf2/

I enabled the privacy plugin yesterday.

Bug description

In our GitHub Actions build pipeline, I see frequent (but not systematic) failures like this:
https://github.com/py-pdf/fpdf2/actions/runs/13388083737/job/37389293893?pr=1366

10:08:50 [mkdocs.material.privacy] Downloading external file: https://api.star-history.com/svg?repos=py-pdf/fpdf2
10:08:51 [mkdocs.commands.build] Error reading page 'index.md': 'content-type'
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.13.2/x64/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ~~~^^
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/mkdocs/__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/mkdocs/commands/build.py", line 310, in build
    _populate_page(file.page, config, files, dirty)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/mkdocs/commands/build.py", line 171, in _populate_page
    page.content = config.plugins.on_page_content(
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        page.content, page=page, config=config, files=files
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/mkdocs/plugins.py", line 638, in on_page_content
    return self.run_event('page_content', html, page=page, config=config, files=files)
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/mkdocs/plugins.py", line 566, in run_event
    result = method(item, **kwargs)
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/material/plugins/privacy/plugin.py", line 148, in on_page_content
    self._queue(url, config, concurrent = True)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/material/plugins/privacy/plugin.py", line 383, in _queue
    self._fetch(file, config)
    ~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/material/plugins/privacy/plugin.py", line 421, in _fetch
    mime = res.headers["content-type"].split(";")[0]
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/requests/structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
           ~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'content-

On other executions, it sometimes work fine:
https://github.com/py-pdf/fpdf2/actions/runs/13387513920/job/37389309336 (retried, the 1st execution failed)

10:09:02 [mkdocs.material.privacy] Downloading external file: https://api.star-history.com/svg?repos=py-pdf/fpdf2

All is fine, but we can see that the with-pdf plugin has trouble downloading this image:

ERROR:weasyprint:Failed to load image at 'https://api.star-history.com/svg?repos=py-pdf/fpdf2': TimeoutError: The read operation timed out
ERROR:weasyprint:Failed to load image at 'data:application/pdf;base64,JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9GaWx0ZXIgL0ZsYXRlRGVjb2RlIC9MZW5ndGggNzM+PgpzdHJlYW0KeJwzUvDiMtAzNVco53IKUdB3M1QwsdAzMFAISVNwDQEJGRvqGVoomJub6hmaKISkKGhkpObk5CuU5xflpGgqhGSBlAEAC64QcgplbmRzdHJlYW0KZW5kb2JqCjEgMCBvYmoKPDwvVHlwZSAvUGFnZXMKL0tpZHMgWzMgMCBSXQovQ291bnQgMQovTWVkaWFCb3ggWzAgMCA1OTUuMjggODQxLjg5XQo+PgplbmRvYmoKNSAwIG9iago8PC9UeXBlIC9Gb250Ci9CYXNlRm9udCAvSGVsdmV0aWNhCi9TdWJ0eXBlIC9UeXBlMQovRW5jb2RpbmcgL1dpbkFuc2lFbmNvZGluZwo+PgplbmRvYmoKMiAwIG9iago8PAovUHJvY1NldCBbL1BERiAvVGV4dCAvSW1hZ2VCIC9JbWFnZUMgL0ltYWdlSV0KL0ZvbnQgPDwKL0YxIDUgMCBSCj4+Ci9YT2JqZWN0IDw8Cj4+Cj4+CmVuZG9iago2IDAgb2JqCjw8Ci9DcmVhdGlvbkRhdGUgKEQ6MjAyMjA5MTUwNjU0NDJaMDYnNTQnKQo+PgplbmRvYmoKNyAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMSAwIFIKL09wZW5BY3Rpb24gWzMgMCBSIC9GaXRIIG51bGxdCi9QYWdlTGF5b3V0IC9PbmVDb2x1bW4KPj4KZW5kb2JqCnhyZWYKMCA4CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMD

I suspect that in some cases the HTTP retrieval of the SVG fails, but the plugin still tries to parse the headers ftom the HTTP response, they do not contain any Content-Type.

In that case, I would expect the privacy plugin to skip that <img> and preserve it as it is.

Related links

Reproduction

9.6.4-privacy-plugin-frequent-keyerror-content-type.zip

Steps to reproduce

Repeatedly call mkdoc build until it fails.

I could not reproduce the failure on my own computer, it only frequently fails in GitHub Actions pipelines.

If this disqualify this bug report, feel free to close it.

Browser

No response

Before submitting

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0