{"record":{"id":"b812bb7d6a8ec491","repo":"TheAlgorithms/Python","slug":"base-must-be-36","errorCode":null,"errorMessage":"base must be <= 36","messagePattern":"base must be <= 36","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"conversions/decimal_to_any.py","lineNumber":71,"sourceCode":"    ValueError: base must be >= 2\n    >>> # a base greater than 36 will error\n    >>> decimal_to_any(34, 37) # doctest: +ELLIPSIS\n    Traceback (most recent call last):\n        ...\n    ValueError: base must be <= 36\n    \"\"\"\n    if isinstance(num, float):\n        raise TypeError(\"int() can't convert non-string with explicit base\")\n    if num < 0:\n        raise ValueError(\"parameter must be positive int\")\n    if isinstance(base, str):\n        raise TypeError(\"'str' object cannot be interpreted as an integer\")\n    if isinstance(base, float):\n        raise TypeError(\"'float' object cannot be interpreted as an integer\")\n    if base in (0, 1):\n        raise ValueError(\"base must be >= 2\")\n    if base > 36:\n        raise ValueError(\"base must be <= 36\")\n    new_value = \"\"\n    mod = 0\n    div = 0\n    while div != 1:\n        div, mod = divmod(num, base)\n        if base >= 11 and 9 < mod < 36:\n            actual_value = ALPHABET_VALUES[str(mod)]\n        else:\n            actual_value = str(mod)\n        new_value += actual_value\n        div = num // base\n        num = div\n        if div == 0:\n            return str(new_value[::-1])\n        elif div == 1:\n            new_value += str(div)\n            return str(new_value[::-1])\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/decimal_to_any.py#L53-L89","documentation":"Raised by decimal_to_any(num, base) in conversions/decimal_to_any.py:71 when base exceeds 36. The digit alphabet is 0-9 plus A-Z (26 letters), i.e. exactly 36 symbols, so bases above 36 have no representable digit set in this implementation and are rejected with a ValueError.","triggerScenarios":"decimal_to_any(34, 37), decimal_to_any(999999, 62) (base64-style radix), or bases taken from specs that assume base62/base64 support which this library does not provide.","commonSituations":"Porting code that uses base36/base62 URL-shortener IDs and assuming arbitrary radix support; passing a base read from a spec or config that allows > 36; confusing bit-width or alphabet length with a valid radix.","solutions":["Cap the radix at 36, or use 36 itself if you just need a compact encoding","If you truly need base > 36, switch to a library that supports arbitrary alphabets (e.g. python-baseconv, base62) instead of this function","Range-check user-supplied bases (2..36) before calling decimal_to_any"],"exampleFix":"# before\ndecimal_to_any(user_id, 62)  # ValueError\n\n# after\nfrom baseconv import Base62\nBase62.encode(user_id)","handlingStrategy":"validation","validationCode":"if not 2 <= base <= 36:\n    raise ValueError(f\"base {base} unsupported; this library covers 2..36 only\")","typeGuard":null,"tryCatchPattern":"try:\n    decimal_to_any(num, base)\nexcept ValueError as e:\n    if 'base must be <= 36' in str(e):\n        num = decimal_to_any(num, 36)  # or switch to a base62 library\n    else:\n        raise","preventionTips":["Document the 2..36 radix contract wherever the API is exposed","For base62/base64 needs, pick a dedicated encoding library up front","Add a unit test asserting your pipeline never emits a radix outside 2..36"],"tags":["python","value-error","radix","base-conversion"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}