{"id":"01594e06ca085451","repo":"pypa/pip","slug":"unknown-directionality-in-label-label-r-at-posit","errorCode":null,"errorMessage":"Unknown directionality in label {label!r} at position {idx}","messagePattern":"Unknown directionality in label (.+?) at position (.+?)","errorType":"validation","errorClass":"IDNABidiError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/idna/core.py","lineNumber":123,"sourceCode":"    bidirectional categories ``R``, ``AL``, or ``AN``); set ``check_ltr``\n    to ``True`` to apply it to LTR-only labels as well.\n\n    :param label: The label to validate, as a Unicode string.\n    :param check_ltr: If ``True``, apply the rules even when the label\n        contains no RTL characters.\n    :returns: ``True`` if the label satisfies the Bidi Rule.\n    :raises IDNABidiError: If any of Bidi Rule conditions 1-6 are violated,\n        or if the directional category of a codepoint cannot be determined.\n    \"\"\"\n    if len(label) > _max_input_length:\n        raise IDNAError(\"Label too long\")\n    # Bidi rules should only be applied if string contains RTL characters\n    bidi_label = False\n    for idx, cp in enumerate(label, 1):\n        direction = unicodedata.bidirectional(cp)\n        if direction == \"\":\n            # String likely comes from a newer version of Unicode\n            raise IDNABidiError(f\"Unknown directionality in label {label!r} at position {idx}\")\n        if direction in _bidi_rtl_categories:\n            bidi_label = True\n    if not bidi_label and not check_ltr:\n        return True\n\n    # Bidi rule 1\n    direction = unicodedata.bidirectional(label[0])\n    if direction in _bidi_rtl_first:\n        rtl = True\n    elif direction == \"L\":\n        rtl = False\n    else:\n        raise IDNABidiError(f\"First codepoint in label {label!r} must be directionality L, R or AL\")\n\n    valid_ending = False\n    number_type: Optional[str] = None\n    for idx, cp in enumerate(label, 1):\n        direction = unicodedata.bidirectional(cp)","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/idna/core.py#L105-L141","documentation":"Raised inside check_bidi (idna IDNABidiError) when unicodedata.bidirectional(cp) returns an empty string for some codepoint in the label. An empty bidi category means the running Python's unicodedata module predates the Unicode version that defines that codepoint, so idna cannot classify its directionality.","triggerScenarios":"Encoding a domain containing a codepoint introduced in a Unicode version newer than the one compiled into the running CPython (e.g. a new emoji or historic script on Python built against Unicode 12 when the char is from Unicode 14). The label also must contain an RTL character (or check_ltr=True) for check_bidi to be reached.","commonSituations":"Running an older Python (e.g. 3.6/3.7) against modern domain data; shipping an app with a frozen/old runtime that lacks recent Unicode tables; CI on an old distro Python processing user-provided internationalized domains.","solutions":["Upgrade Python to a release built against a newer Unicode version (CPython embeds the Unicode database at build time).","Filter or reject input containing codepoints the runtime cannot classify before passing to idna.","If on a managed runtime, install one bundled with up-to-date Unicode tables (e.g. python3.11+)."],"exampleFix":"# before\nidna.encode('\\U0001FA00somearabic\\u0627')  # Unknown directionality on old Python\n\n# after\n# upgrade runtime, or pre-filter:\nif any(unicodedata.bidirectional(c) == '' for c in label):\n    raise ValueError('label uses unsupported codepoints for this runtime')\nidna.encode(label)","handlingStrategy":"validation","validationCode":"import unicodedata\ndef runtime_supports_label(label: str) -> bool:\n    return all(unicodedata.bidirectional(c) != '' for c in label)","typeGuard":"import unicodedata\ndef is_label_bidi_known(label: str) -> bool:\n    return all(unicodedata.bidirectional(c) for c in label)","tryCatchPattern":"from idna import IDNABidiError, encode\ntry:\n    encode(label)\nexcept IDNABidiError as e:\n    if 'Unknown directionality' in str(e):\n        # runtime Unicode tables are too old for this codepoint\n        raise ValueError('upgrade Python runtime for this label') from e\n    raise","preventionTips":["Run on a recent CPython whose bundled Unicode database covers your input.","Pre-filter labels: reject any codepoint whose unicodedata.bidirectional is empty.","Pin your runtime version in CI to one known to support the scripts in your data."],"tags":["idna","unicode","bidi","runtime-version","pip"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}