The error

  HangupException

  The remote server unexpectedly closed the connection.

  at /usr/local/lib/python3.10/site-packages/dulwich/protocol.py:215 in read_pkt_line
      211β”‚ 
      212β”‚         try:
      213β”‚             sizestr = read(4)
      214β”‚             if not sizestr:
    β†’ 215β”‚                 raise HangupException
      216β”‚             size = int(sizestr, 16)
      217β”‚             if size == 0 or size == 1:  # flush-pkt or delim-pkt
      218β”‚                 if self.report_activity:
      219β”‚                     self.report_activity(4, "read")

The following error occurred when trying to handle this error:


  HangupException

  Host key verification failed.

  at /usr/local/lib/python3.10/site-packages/dulwich/client.py:1154 in fetch_pack
      1150β”‚         with proto:
      1151β”‚             try:
      1152β”‚                 refs, server_capabilities = read_pkt_refs(proto.read_pkt_seq())
      1153β”‚             except HangupException as exc:
    β†’ 1154β”‚                 raise _remote_error_from_stderr(stderr) from exc
      1155β”‚             (
      1156β”‚                 negotiated_capabilities,
      1157β”‚                 symrefs,
      1158β”‚                 agent,

Cannot install marker.

------
Dockerfile:32
--------------------
  30 |     COPY poetry.lock pyproject.toml ./
  31 |     
  32 | >>> RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root

Where I encountered the error

I was trying to install packages with poetry in a Dockerfile.

How I traced it

There was no mention of dulwitch in poetry.lock or pyproject.toml. So it must come from poetry itself.

  • I bumped poetry from 1.7.0 to 1.7.1 β†’ no change

Then I noticed this post on stack: https://stackoverflow.com/questions/74523531/importing-github-repo-as-dependency-in-poetry-in-docker-container

I checked my poetry.toml and found this:

marker = {git = "git@github.com:VikParuchuri/marker.git"}

I was installing one of the dependencies from source using git. I changed it to https:

marker = {git = "https://github.com/VikParuchuri/marker.git"}

And the error went away ;)

More on that here: https://github.com/python-poetry/poetry/issues/6999