# Fix 'API' object has no attribute 'search' After a Tweepy Upgrade

Yes. An agent reproduces the AttributeError on Tweepy 4, moves the call to search_tweets, drops the parameters v4 rejects and opens a PR with both runs quoted.

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

## What the agent does

The agent clones the repository into its own cloud sandbox and reads the Twitter calls first. In a small Flask app like Smerity/trending_arxiv, `main.py` builds `tweepy.OAuthHandler` at line 25 and `tweepy.API(auth)` at line 28 from keys in `config.yaml`, then `fetch_timeline` calls `api.user_timeline(screen_name=username, count=200, page=0)` at line 178, `fetch_search` calls `api.search('@{} arxiv.org'.format(username), count=200)` at line 183, and the `/rate_limits` route calls `api.rate_limit_status()` at line 213. `add_tweet` reads `tweet.entities['urls']`, `tweet.user.id`, `tweet.user.screen_name`, `tweet._json` and `retweeted_status` from each result. `requirements.txt` names `tweepy` with no version beside `flask`, `Flask-SQLAlchemy`, `gevent`, `untangle` and `pyyaml`, and `run_dev_server.sh` starts it with `python -m flask run`.

Then it reproduces both states with placeholder keys, which is enough because the break happens before any request is sent. A fresh install resolves Tweepy 4.17.0, and `api.search(...)` raises `AttributeError: 'API' object has no attribute 'search'`; `search_tweets` exists on the same object with the signature `(q, **kwargs)`. On `tweepy<4`, which resolves 3.10.0, `search` exists and `search_tweets` does not. Two more v4 changes show up on the same object: `OAuthHandler` now prints `DeprecationWarning: OAuthHandler is deprecated; use OAuth1UserHandler instead`, and the `page=0` argument on `user_timeline` logs `WARNING:tweepy.api:Unexpected parameter: page` before the call, because v4 no longer takes it. `rate_limit_status` is unchanged.

The fix is three lines. Line 183 becomes `api.search_tweets(q='@{} arxiv.org'.format(username), count=200)`, with the query passed by keyword as the new signature requires; line 178 drops `page=0`, since the first page is the default and the name is ignored; line 25 constructs `tweepy.OAuth1UserHandler` with the same four values. `add_tweet` needs no change, because the `Status` objects v4 returns carry the same `entities`, `user` and `_json` attributes the function reads. The agent pins the floor with `tweepy>=4` in `requirements.txt`, since the old method name no longer exists anywhere the new one does.

What the run cannot check, it says. With placeholder keys every call ends in `401 Unauthorized` after the warnings, so the pull request shows the attribute and signature checks and the warnings, and leaves the live fetch to the owner's keys. It also notes that whether an account's API tier still allows the v1.1 search endpoint is a question of the account, not the library.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "This Flask app fails with \"AttributeError: 'API' object has no attribute 'search'\" after a tweepy upgrade. Read requirements.txt, config.yaml and every file that calls the tweepy API first. Install the current tweepy and, with placeholder credentials, build the API object the app builds and quote the AttributeError and every deprecation or unexpected-parameter warning the app's calls produce; then install tweepy 3 and show the same calls resolve. Move each removed call to its v4 name with the keyword arguments v4 requires, drop any parameter v4 ignores, replace deprecated auth classes, check that the attributes the app reads from each result still exist, and add the minimum tweepy version to requirements.txt. Say which calls could not be exercised without real credentials. Open a pull request that quotes the failing and passing checks.",
  "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

What comes back is a pull request touching `main.py` and `requirements.txt`: `search` renamed to `search_tweets` with `q=` on line 183, `page=0` removed from line 178, `OAuth1UserHandler` on line 25, and `tweepy>=4` in the requirements. The description quotes the `AttributeError` on 4.17.0, the `Unexpected parameter: page` warning and the `OAuthHandler` deprecation, the `search` attribute present on 3.10.0, the `(q, **kwargs)` signature of the replacement, and a line saying the live fetch ended `401 Unauthorized` with placeholder keys.

A reviewer checks that the query string is unchanged apart from being passed by keyword, that no other `api.` call in the repository uses a name v4 removed, and that the fields `add_tweet` reads still exist on the result objects. The run's record holds each install and each call with its full output, so the version boundary can be read rather than taken on trust.

## Run it on every Monday morning

Add an automation to the Project with this prompt and a `schedule` trigger, `cron` set to `0 9 * * 1` in your `timezone`. Each Monday one run installs the current tweepy, exercises the app's calls with placeholder keys and opens one pull request on its own branch when a name moved; a week where nothing changed opens nothing, and a week where a replacement cannot be found ends `needs_review` with the error attached.

The same body works from your own code with `POST /o/{org}/sessions` and an API key when a dependency bot's tweepy bump turns the deploy red; send a `request_id` that is a UUID v5 of the bot's pull request number so a retried start returns the same run, and the key's `webhook_url` receives `run.completed` or `run.failed` with the session URL when it ends.

## Why run it on Rush?

Renames like this one hide behind a network call, so a laptop with real keys finds them one failed request at a time. The agent's sandbox needs no keys for the part that broke: it builds the same objects the app builds, reads their attributes and signatures on the old and new release, and keeps every command and warning in the run's record, so the pull request names each change with the release that made it.

A library that talks to a paid API also raises a question the code cannot answer, which is whether the account still has access to the endpoint. The agent separates the two in the pull request: the renames it proved, and the live call it could not make, so the owner knows exactly what one run with real credentials still has to confirm.

## Frequently asked questions

### Why was search renamed?

Tweepy 4.0 renamed the v1.1 methods to match the endpoint names, so `search` became `search_tweets`, and several names that collided with other endpoints were dropped. The new method takes the query as `q` and keyword arguments only, which is why the positional string in the old call has to move.

### What does the page parameter warning mean?

v4's `user_timeline` no longer takes `page`; it logs `Unexpected parameter: page` and sends the request without it. The call still works, so the agent removes the argument rather than mapping it, and notes that pagination in v4 goes through `tweepy.Cursor` if more than one page is ever needed.

### Will the agent keep OAuthHandler?

It still works in 4.x as an alias, but it prints a `DeprecationWarning` on every start. The agent replaces it with `OAuth1UserHandler`, which takes the same consumer and access values, so the config file does not change.

### Can it test the real fetch?

Not with placeholder credentials; every call after the attribute checks ends `401 Unauthorized`. Put real keys in a Project secret and name the secret in the prompt if you want the run to fetch a timeline and show `add_tweet` storing it, and remember that access to the v1.1 search endpoint depends on the account's API tier.

## More Tweepy jobs

- [Fix "AttributeError: module 'tweepy' has no attribute 'StreamListener'"](https://getrush.ai/run/fix-tweepy-streamlistener-attribute-error/tweepy/)

## More jobs like this: Upgrade dependencies weekly

- [Fix "AttributeError: module 'ast' has no attribute 'Str'" on Python 3.14](https://getrush.ai/run/fix-ast-str-attribute-error/ast/)
- [Fix "Bad Argument Type. Starting with v5, Only the Object Form Is Allowed" After a TanStack Query Upgrade](https://getrush.ai/run/fix-bad-argument-type-only-object-form-allowed/tanstack-query/)
- [Fix the Browserslist caniuse-lite Is Outdated Warning](https://getrush.ai/run/fix-caniuse-lite-is-outdated-warning/browserslist/)
- [Fix Cannot Find Module @babel/core After a babel-loader Upgrade](https://getrush.ai/run/fix-cannot-find-module-babel-core/babel-loader/)
- [Fix "Cannot Import Name 'Imputer' from 'sklearn.preprocessing'" After a scikit-learn Upgrade](https://getrush.ai/run/fix-cannot-import-name-imputer-from-sklearn-preprocessing/scikit-learn/)

## 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/)
