python-poetry/poetry · error · RuntimeError
Repository {repository_name} is not defined
Error message
Repository {repository_name} is not defined What it means
Raised by Publisher.publish() when a repository_name is supplied but Poetry's config has no repositories.<name>.url entry. Poetry needs an explicit URL to know where to upload; an undefined name is treated as a configuration error rather than guessing.
Source
Thrown at src/poetry/publishing/publisher.py:60
def publish(
self,
repository_name: str | None,
username: str | None,
password: str | None,
cert: Path | None = None,
client_cert: Path | None = None,
dry_run: bool = False,
skip_existing: bool = False,
) -> None:
if not repository_name:
url = "https://upload.pypi.org/legacy/"
repository_name = "pypi"
else:
# Retrieving config information
url = self._poetry.config.get(["repositories", repository_name, "url"])
if url is None:
raise RuntimeError(f"Repository {repository_name} is not defined")
url = _normalize_legacy_repository_url(url)
if not (username and password):
# Check if we have a token first
token = self._authenticator.get_pypi_token(repository_name)
if token:
logger.debug("Found an API token for %s.", repository_name)
username = "__token__"
password = token
else:
auth = self._authenticator.get_http_auth(repository_name)
if auth:
logger.debug(
"Found authentication information for %s.", repository_name
)
username = auth.username
password = auth.password
View on GitHub (pinned to 92b74dcfe3)
Solutions
- Register the repository: `poetry config repositories.<name> <url>`.
- Double-check the name passed to `--repository`/`-r` matches the configured key exactly (case-sensitive).
- If the URL is in a different config scope, set it explicitly (`--local` for project-level, default for global).
- For one-off use, fall back to the default PyPI by omitting `-r`.
Example fix
// before $ poetry publish -r internal RuntimeError: Repository internal is not defined // after $ poetry config repositories.internal https://internal.pypi/simple/ $ poetry publish -r internal
Defensive patterns
Strategy: validation
Validate before calling
def repository_is_configured(config, name: str) -> bool:
return config.get(["repositories", name, "url"]) is not None Try / catch
from poetry.publishing.publisher import Publisher
try:
publisher.publish(repository_name=name, username=u, password=p)
except RuntimeError as e:
if "is not defined" in str(e):
# register the repository then retry
... Prevention
- Configure repositories with `poetry config repositories.<name> <url>` before publishing.
- Document required `poetry config` commands in the project setup guide.
- Use a pre-publish script that asserts the repository is configured.
- Double-check the repository name spelling on the CLI.
When it happens
Trigger: Running `poetry publish -r myrepo` (or passing repository_name='myrepo') when `poetry config repositories.myrepo.url` was never set. The lookup `config.get(['repositories', repository_name, 'url'])` returns None.
Common situations: Forgot to configure the repository before publishing; typo in the repository name on the CLI vs. config; config stored in a different scope (local vs global) than the one being read; new team member who hasn't run the config commands.
Related errors
- The name [pypi] is reserved for repositories
- Key {'.'.join(keys)} not in config
- Key {'.'.join(keys)} not in config
- You must pass exactly 1 value
- Invalid build config setting '{value}'. It must be a valid J
AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04).
Data as JSON: /data/errors/3c4e495bf4028b59.json.
Report an issue: GitHub.