# Fix "ModuleNotFoundError: No module named 'crypt'" on Python 3.13

Yes. An agent finds which logins still reach the removed crypt module, replaces the call with a tested equivalent, and shows the password hashes still verify.

[Run this on Rush](https://cloud.getrush.ai/run/fix-no-module-named-crypt/crypt/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

Python 3.13 removed the `crypt` module. Where the import sits decides who is locked out, so the agent maps that first. In bugy/script-server the import is not at the top of a file. It is line 127 of `src/auth/auth_htpasswd.py`, inside `verify()`, in the last branch of a chain: entries starting `$2y$` go to `bcrypt`, `$apr1$` entries to the project's own MD5 routine, `{SHA}` entries to SHA-1, and anything else on a non-Windows host to `crypt.crypt(password, existing_password[:2])`. That branch belongs to the built-in verifier, which the server uses only when the `htpasswd` program is not installed; when it is, a different class shells out to `htpasswd -bv` and never touches the module. So on 3.13 the server starts, most users sign in, and the failure belongs to one group: accounts whose line in the htpasswd file is in the traditional crypt format, on a machine without Apache's utilities.

The repository's tests describe that group exactly, and the agent uses them as its measure. `src/tests/auth/test_auth_htpasswd.py` runs every case twice, once per verifier, with four crypt-format users in its sample file. The agent installs `apache2-utils` first, as the project's `.travis.yml` does, because without the `htpasswd` program half the cases cannot run at all. On Python 3.12 all 26 tests pass and the log carries `DeprecationWarning: 'crypt' is deprecated and slated for removal in Python 3.13`. On 3.13 two fail, both in the built-in class, `test_authenticate_success_when_crypt` and `test_authenticate_failure_when_crypt_with_plain_password`, each with the message in the title.

Then it picks a replacement by running the candidates against the hashes in that test file. A package that provides the old function under another name is the smallest change: with `legacycrypt` imported in place of `crypt`, all 26 tests pass on 3.13 with one line edited. `passlib`'s `des_crypt.verify` gives the same answers through a different API. A third package, `crypt-r`, is a C extension, and where no prebuilt wheel fits the host, installing it needs a compiler; that matters for a project whose `pyproject.toml` lists only `tornado`. There is also an option that adds no package: treat crypt entries the way the file already treats bcrypt ones, where the verifier's constructor raises a configuration error telling the operator to install the `htpasswd` utility or the missing package. The agent presents these with the test result for each and takes the one that matches how the project already handles an optional dependency.

While it is in the branch it reports what the old call was doing. The salt argument is the first two characters of the stored hash, so only the original DES scheme is handled, and that scheme reads just the first eight characters of a password. The test user whose password is `some_long_password` also verifies with any other string that starts `some_lon`. The agent does not change which formats the server accepts. It states the fact in the pull request so the maintainers can decide whether to keep the format at all.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "On Python 3.13 this project fails with \"ModuleNotFoundError: No module named 'crypt'\". Find every import of the crypt module, including imports inside functions, and for each one say which users or commands reach it and under what configuration; the service may start normally and fail only for some logins. Install any system packages the test suite needs, then run the relevant tests on Python 3.12 and on Python 3.13 and save both results, including the deprecation warning on 3.12. Replace the crypt call. Compare at least these options against the password hashes the tests already contain, and report the test result for each: a package that provides the same crypt() function, a password-hashing library's verify function, and failing at start-up with a clear configuration error when the password file contains entries that need crypt and nothing can check them. Prefer the option that fits how the project already treats its optional dependencies, and say if an option needs a C compiler to install. Do not change which password formats are accepted and do not rewrite or rehash anyone's stored password. Report, without changing it, which crypt scheme the existing call supports and any weakness of that scheme you can demonstrate with the test data. Finish with the full test suite on 3.12 and 3.13. Open a pull request with the before and after results and anything you noticed but left alone.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request that touches `src/auth/auth_htpasswd.py` and, depending on the option, the dependency list or the start-up check. The description gives the two test runs side by side, 26 passing on 3.12 and two failing on 3.13, then the same suite on 3.13 after the change. It names the two failing tests, since they are the proof that the fix reaches the right branch, and it records that the system package for `htpasswd` was installed before either run.

A reviewer checks that the comparison of hashes is unchanged: the same stored strings, the same accepted passwords, no migration. If the chosen option is a new package, they check that it is imported inside the branch, as `bcrypt` is, so installations without crypt-format users need nothing new. The note about the eight-character limit is for the maintainers and is not acted on. If a test still fails on 3.13, the agent reports it instead of presenting the work as finished.

## Run it on every login error after a Python upgrade

The affected users see only that they cannot sign in after the host's Python moved, while everyone else can. The exception itself goes wherever the server's errors go, usually an error tracker. Most error trackers sign their own webhook deliveries and cannot send the `Authorization: Bearer` header a Rush `webhook` trigger requires, so put a small handler on your server between them. It keeps events whose message contains `No module named 'crypt'` and posts the traceback to the trigger's URL with the trigger's secret.

The posted body is placed after the saved prompt as event text. Every affected login raises the same exception, so the handler should send an `Idempotency-Key` header to the trigger's URL made from the error's fingerprint, and the automation's max runs per hour should be low; one run fixes the branch for everyone.

## Why run it on Rush?

The bug lives in a combination: a specific interpreter, a missing system program and one kind of line in a password file. Reproducing it on a laptop means arranging all three, and most laptops have the `htpasswd` program or an older Python and so show nothing. In its own sandbox the agent installs or omits each piece deliberately, runs the suite under both interpreters, and the output of each run stays with the session for the reviewer to read.

Authentication code also deserves a second opinion that can be checked. Swapping a password function by hand invites a silent change in which strings are accepted. Here each candidate is run against the fixed hashes in the repository's own tests, the results are listed per candidate, and the pull request shows the commands that produced them.

## Frequently asked questions

### What replaces the crypt module in Python 3.13?

There is no standard-library replacement for `crypt.crypt()`. Options are a package that provides the same function, such as `legacycrypt` or `crypt-r`, a hashing library's verifier such as `passlib`'s `des_crypt`, or `hashlib` and `bcrypt` if you can move to a different scheme. Which is right depends on the hashes you already store.

### Why does the service start and only some logins fail?

Because the import is inside a function that only some accounts reach. A module imported at the top of a file fails at start-up; one imported in a branch fails when that branch runs. The agent maps the branches before fixing anything so the pull request can say who was affected.

### Will users have to reset their passwords?

No. The replacement computes the same hash from the same stored string, and the prompt forbids rehashing. The existing tests, which hold fixed hashes and their passwords, are the check that nothing changed.

### Is the traditional crypt format safe to keep?

It is weak: it uses only the first eight characters of a password. The agent demonstrates that with the repository's test data and reports it, but dropping a supported format is a product decision, so it leaves the choice with the maintainers.

## More jobs like this: Fix a bug from an alert

- [Fix "ModuleNotFoundError: No module named 'dash_core_components'"](https://getrush.ai/run/fix-no-module-named-dash-core-components/dash/)
- [Fix "ModuleNotFoundError: No module named 'fabric.api'" by Porting a fabfile to Fabric 3](https://getrush.ai/run/fix-no-module-named-fabric-api/fabric/)
- [Fix "ModuleNotFoundError: No module named 'imghdr'" on Python 3.13](https://getrush.ai/run/fix-no-module-named-imghdr/imghdr/)
- [Fix ModuleNotFoundError: No module named 'imp' on Python 3.12](https://getrush.ai/run/fix-no-module-named-imp/imp/)
- [Fix "ModuleNotFoundError: No module named 'imp'" on Python 3.12](https://getrush.ai/run/fix-no-module-named-imp/python/)
- [Fix "ModuleNotFoundError: No module named 'kafka.vendor.six.moves'" on Python 3.12](https://getrush.ai/run/fix-no-module-named-kafka-vendor-six-moves/kafka-python/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
