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

error with field edit_history_tweet_ids #1994

Open
liabozarth opened this issue Oct 28, 2022 · 3 comments
Open

error with field edit_history_tweet_ids #1994

liabozarth opened this issue Oct 28, 2022 · 3 comments
Labels
API This is regarding Twitter's API Improvement This is regarding an improvement to an existing feature

Comments

@liabozarth
Copy link

This appears to be an error with the Tweet.py file

Stream encountered an exception Traceback (most recent call last): File "/home/ciptools/data-loaders/covid19-api-v2/venv/lib/python3.9/site-packages/tweepy/streaming.py", line 92, in _connect self.on_data(line) File "/home/ciptools/data-loaders/covid19-api-v2/venv/lib/python3.9/site-packages/tweepy/streaming.py", line 926, in on_data includes = self._process_includes(data["includes"]) File "/home/ciptools/data-loaders/covid19-api-v2/venv/lib/python3.9/site-packages/tweepy/client.py", line 164, in _process_includes includes["tweets"] = [Tweet(tweet) for tweet in includes["tweets"]] File "/home/ciptools/data-loaders/covid19-api-v2/venv/lib/python3.9/site-packages/tweepy/client.py", line 164, in <listcomp> includes["tweets"] = [Tweet(tweet) for tweet in includes["tweets"]] File "/home/ciptools/data-loaders/covid19-api-v2/venv/lib/python3.9/site-packages/tweepy/tweet.py", line 121, in __init__ map(int, data["edit_history_tweet_ids"]) KeyError: 'edit_history_tweet_ids'

My code

`

# This is where we set our filter rule
streamer.add_rule()

expansions =  "author_id,referenced_tweets.id,in_reply_to_user_id,geo.place_id,entities.mentions.username,referenced_tweets.id.author_id",
user_fields =  "created_at,description,entities,id,location,name,protected,public_metrics,url,username,verified,withheld",
tweet_fields= "attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,public_metrics,possibly_sensitive,referenced_tweets,source,text,withheld",
place_fields= "contained_within,country,country_code,full_name,geo,id,name,place_type",

#return hydrated tweet
cs.filter(user_fields=user_fields, tweet_fields=tweet_fields, place_fields=place_fields, expansions=expansions)

`

@Harmon758
Copy link
Member

This seems like it might be a bug with the Twitter API, since edit_history_tweet_ids should be a default Tweet field.

For code block usage, see https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks.

@Harmon758 Harmon758 added the API This is regarding Twitter's API label Oct 28, 2022
@meiji163
Copy link

meiji163 commented Oct 30, 2022

This is also breaking my existing code using 4.12 when I initialize a tweepy.Tweet from a dict (for testing purposes)

import tweepy
tweepy.Tweet(data={"id":1, "text":"example"})
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/home/meiji163/miniconda3/lib/python3.8/site-packages/tweepy/tweet.py", line 128, in __init__
   map(int, data["edit_history_tweet_ids"])
KeyError: 'edit_history_tweet_ids'

@Harmon758
Copy link
Member

While adding support for the edit metadata, it did occur to me that it might be a breaking change in terms of how Tweet is initialized. I supposed there are possible use cases for wanting to use old data to construct the model. For now, I've changed it to handle the KeyError and warn about it being missing instead, with 3dea0df. This is a stopgap, but I don't really see another way to keep backwards-compatibility when the Twitter API adds new default fields to models.

@Harmon758 Harmon758 added the Improvement This is regarding an improvement to an existing feature label Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API This is regarding Twitter's API Improvement This is regarding an improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants