Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid value 52 for parameter page parameter is invalid. #604

Open
ghost opened this issue May 4, 2015 · 7 comments
Open

Invalid value 52 for parameter page parameter is invalid. #604

ghost opened this issue May 4, 2015 · 7 comments
Labels
Bug This is regarding a bug with the library

Comments

@ghost
Copy link

ghost commented May 4, 2015

Hi I have sample code:

    with open('temp_users.json', 'w') as f:
        all_data = []
        print "Searching users",
        for user in tweepy.Cursor(api.search_users,q = "ziemniaki").items():
            print ".",
            sys.stdout.flush()
            all_data.append(user._json)
        f.write(json.dumps(all_data))
        f.close()
    print ""
    return

And I got this error:
raise TweepError(error_msg, resp)
tweepy.error.TweepError: [{u'message': u'Invalid value 52 for parameter page parameter is invalid.', u'code': 44}]

And second uncaught exception:
    raise TweepError(error_msg, resp)
tweepy.error.TweepError: [{u'message': u'Rate limit exceeded', u'code': 88}]
@AritzBi
Copy link

AritzBi commented Jul 20, 2015

Same problem here, has anyone been able to fix it?

@serkandaglioglu
Copy link

I have same problem. I use as doc - http://docs.tweepy.org/en/v3.2.0/api.html#API.search

results = twitterApi.search(
            q = request.args.get("q"),
            rpp = 50,
            page = 2
        )

But it throws that error "page parameter is invalid"

@qxx
Copy link

qxx commented Apr 18, 2016

It seems the page parameter is not supported. Suggestion: remove 'page' from the docs

@tdatu
Copy link

tdatu commented Oct 4, 2017

I answered this in the stackoverflow. Basically, you can use count param.

@vinog-git
Copy link

Twitter gives you only the first 1000 results for a search. 20 results per page * 50 pages = 1000 results. Hence the next hit with the page number 52 onward gives error (not sure why page 51 works, may be to compensate for one or two results filtered in the previous searches).

Refer: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-search

@Harmon758 Harmon758 added the Bug This is regarding a bug with the library label May 4, 2019
@Harmon758
Copy link
Member

@vinog-git is correct.
The issue is that the users/search endpoint returns an error when attempting to paginate past 1000 results, instead of returning a list of 0 items, as PageIterator expects to raise StopIteration:

tweepy/tweepy/cursor.py

Lines 156 to 171 in 51f680c

class PageIterator(BaseIterator):
def __init__(self, method, args, kargs):
BaseIterator.__init__(self, method, args, kargs)
self.current_page = 0
def next(self):
if self.limit > 0:
if self.current_page > self.limit:
raise StopIteration
items = self.method(page=self.current_page, *self.args, **self.kargs)
if len(items) == 0:
raise StopIteration
self.current_page += 1
return items

@J0G1 Your second exception is simply caused by exceeding the rate limit, as the error says.
See the wait_on_rate_limit parameter for API for a way to handle this.

@serkandaglioglu That is not relevant to this issue, as you're using API.search, (rather than API.search_users) which uses the standard search API and does not have a page parameter.
For updating the documentation for API.search, see #1199. CC: @qxx

@tdatu The count parameter simply specifies the limit for results to return per page.
It does not affect this issue; e.g. count=10 will result in the error Invalid value 102 for parameter page parameter is invalid. when attempting to iterate past the 1000th result.
In fact, since the default and maximum for count is 20, count=100 as in your Stack Overflow answer, does nothing. See the documentation for the users/search endpoint.

@colinobriencork
Copy link

colinobriencork commented Jun 11, 2020

It's because searching for users is limited to return 1000 results through the basic Twitter API:

https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-search

So you can put in .pages(51) and then it won't throw an error. Or, .items(1000) probably, I haven't checked.

If you want to run it again, however, it's just going to give the same 1000 results as before so you'll need to change the query to give different results.

It's just a limitation of the basic Twitter API, not a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is regarding a bug with the library
Projects
None yet
Development

No branches or pull requests

7 participants