TwitterPager: TypeError: 'NoneType' object does not support item assignment
factorlive opened this issue ยท 6 comments
Hi,
Whenever I am about to reach the next page with the helper class TwitterPager, I hit the TypeError below. So I can only retrieve the first page.
Tested on endpoints:
- users/:id/following
- users/:id/tweets
The endpoint in the example does work for me. Also, weirdly, I can retrieve the meta next_token from the r.json() object.
Working with Python 3.9 on Ubuntu 20.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-18-cbcd2388f522> in <module>
24
25 counter = 0
---> 26 for item in pager.get_iterator(new_tweets=False):
27 counter += 1
28 print(counter)
~/.cache/pypoetry/virtualenvs/campaign-IjD-JE0s-py3.9/lib/python3.9/site-packages/TwitterAPI/TwitterPager.py in get_iterator(self, wait, new_tweets)
117 self.params['since_id'] = meta['newest_id']
118 else:
--> 119 self.params['next_token'] = meta['next_token']
120
121 except TwitterRequestError as e:
TypeError: 'NoneType' object does not support item assignment
Any ideas? ๐
Do you have a short code example?
Thanks for the swift response. Yes.
The response gets you the first 100 followers, i.e. first page.
from TwitterAPI import TwitterAPI, TwitterPager
from dotenv import load_dotenv
load_dotenv()
api = TwitterAPI(os.getenv("CONSUMER_KEY"), os.getenv("CONSUMER_SECRET"),
os.getenv("TOKEN"), os.getenv("SECRET"), api_version='2')
pager = TwitterPager(api, 'users/:1314235041841643520/following')
counter = 0
for item in pager.get_iterator(new_tweets=False):
print(item)
counter += 1
print(counter)
When looking at the response object, I do see the next token. The TypeError suggests it was not supplied. I also tried playing with the new_tweets parameter to see whether such would cause the error. However, I had no luck.
from TwitterAPI import TwitterAPI, TwitterPager
from dotenv import load_dotenv
load_dotenv()
api = TwitterAPI(os.getenv("CONSUMER_KEY"), os.getenv("CONSUMER_SECRET"),
os.getenv("TOKEN"), os.getenv("SECRET"), api_version='2')
r = api.request('users/:1314235041841643520/following')
data = r.json()
print(data["meta"]["next_token"])
Okay, I see the issue in the TwitterPager
code. Should have a fix soon.
Well done. Look forward to it. I didn't spot it. The pager is very handy.
๐๐
It should be fixed in version 2.6.6. You can download it now.
Works. โ