python-poetry/poetry · error · UploadError

Error connecting to repository

Error message

Error connecting to repository

What it means

Raised by Uploader._upload_file() in the requests.RequestException handler when the caught exception has no .response — i.e. the request never reached a server response. This covers connection-level failures (DNS, refused connection, TLS, timeout). It is the fallback counterpart to error 71.

Source

Thrown at src/poetry/publishing/uploader.py:292

                    )
                    bar.display()
                else:
                    resp.raise_for_status()

            except requests.RequestException as e:
                if self._io.output.is_decorated():
                    self._io.overwrite(
                        f" - Uploading <c1>{file.name}</c1> <error>FAILED</>"
                    )

                if e.response is not None:
                    message = (
                        f"HTTP Error {e.response.status_code}: "
                        f"{e.response.reason} | {e.response.content!r}"
                    )
                    raise UploadError(message) from e

                raise UploadError("Error connecting to repository") from e

            finally:
                self._io.write_line("")

    def _register(self, session: requests.Session, url: str) -> requests.Response:
        """
        Register a package to a repository.
        """
        data = self.post_data(self.files[0])
        data.update({":action": "submit", "protocol_version": "1"})

        data_to_send = self._prepare_data(data)
        encoder = MultipartEncoder(data_to_send)
        resp = session.post(
            url,
            data=encoder,
            allow_redirects=False,
            headers={"Content-Type": encoder.content_type},

View on GitHub (pinned to 92b74dcfe3)

Solutions

  1. Check connectivity to the repository URL: `curl -v <url>`.
  2. If behind a proxy, configure HTTPS_PROXY / Poetry's proxy settings.
  3. For TLS errors, verify CA certs and the system clock; consider the configured cert options.
  4. Retry on transient network drops; for chronic slowness, review REQUESTS_TIMEOUT and link quality.
  5. Confirm the repository hostname is correct and resolvable.

Example fix

// before: behind corporate proxy, connection fails
UploadError: Error connecting to repository

// after
$ export HTTPS_PROXY=http://proxy.corp:8080
$ poetry publish -r internal
Defensive patterns

Strategy: retry

Validate before calling

import socket

def host_is_reachable(url: str) -> bool:
    from urllib.parse import urlparse
    host = urlparse(url).hostname
    try:
        socket.gethostbyname(host)
        return True
    except OSError:
        return False

Try / catch

from poetry.publishing.uploader import UploadError

import time

for attempt in range(3):
    try:
        publisher.publish(...)
        break
    except UploadError as e:
        if "Error connecting to repository" in str(e) and attempt < 2:
            time.sleep(2 ** attempt)
            continue
        raise

Prevention

When it happens

Trigger: session.post() raises a ConnectionError, ConnectTimeout, SSLError, or ReadTimeout before any HTTP response is received; the handler sees e.response is None and raises UploadError('Error connecting to repository').

Common situations: No/lost internet connectivity; DNS resolution failure for the index hostname; corporate proxy or firewall blocking the upload; TLS certificate verification failure; the index server is down; REQUESTS_TIMEOUT exceeded on a slow link.

Related errors


AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04). Data as JSON: /data/errors/4a7663004a1d978e.json. Report an issue: GitHub.