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

A Failed None Check causing a Error to attempt to call a function of NoneType Line 269 on twDataTypes #210

Closed
TheLiveitup34 opened this issue Sep 12, 2024 · 9 comments

Comments

@TheLiveitup34
Copy link

In short I looked into the find_objects and seen it returns None when no value is found and the error came up of it attempting to call the function of a NoneType.

def _format_tweet(self):
        self._check_if_protected()
        self._tweet = find_objects(self._raw, "__typename", ["Tweet", "TweetWithVisibilityResults"], recursive=False)
        // code here fails to detect if  self._tweet is a value of None value and will fail with error trace back below
        if self._tweet.get('tweet'):
            self._tweet = self._tweet['tweet']
Traceback (most recent call last):
  File "/home/user/Tweety-archiver/main.py", line 190, in <module>
    modify_tweet(app.tweet_detail(manual))
  File "/home/user/.local/lib/python3.10/site-packages/tweety/bot.py", line 863, in tweet_detail
    tweet = Tweet(self, entry, response)
  File "/home/user/.local/lib/python3.10/site-packages/tweety/types/twDataTypes.py", line 46, in new_init
    init(self, *_args, **_kwargs) # noqa
  File "/home/user/.local/lib/python3.10/site-packages/tweety/types/twDataTypes.py", line 166, in __init__
    self._format_tweet()
  File "/home/user/.local/lib/python3.10/site-packages/tweety/types/twDataTypes.py", line 269, in _format_tweet
    if self._tweet.get('tweet'):
AttributeError: 'NoneType' object has no attribute 'get'
@mahrtayyab
Copy link
Owner

if you are comfortable , can you please share tweet id which caused this error

@TheLiveitup34
Copy link
Author

Yes I'm more than comfortable i built the program to use the code you wrote to archive club penguin tweets for a friend and it may not be available to you due to it going private after closure but we're using a logged in session that has access to the tweets

Tweet id:993640176751538177

@mahrtayyab
Copy link
Owner

650981c

@Tyviebrock
Copy link

image

Can confirm this issue is still occurring on the latest version

@mahrtayyab
Copy link
Owner

can you please specify version your are using.

@Tyviebrock
Copy link

Version 2.0.1

@TheLiveitup34
Copy link
Author

TheLiveitup34 commented Nov 23, 2024

to add to note to what he is saying
` def find_objects(obj, key, value, recursive=True, none_value=None):
results = []

def find_matching_objects(_obj, _key, _value):
    if isinstance(_obj, dict):
        if _key in _obj:
            found = False
            if _value is None:
                found = True
                results.append(_obj[_key])
            elif (isinstance(_value, list) and _obj[_key] in _value) or _obj[_key] == _value:
                found = True
                results.append(_obj)

            if not recursive and found:
                return results[0]

        for sub_obj in _obj.values():
            find_matching_objects(sub_obj, _key, _value)
    elif isinstance(_obj, list):
        for item in _obj:
            find_matching_objects(item, _key, _value)

find_matching_objects(obj, key, value)

if len(results) == 1:
    return results[0]

if len(results) == 0:
 // returns None here 
    return none_value

if not recursive:
    return results[0]

return results

`
your function called in line 268
of twDataTypes.py

def _format_tweet(self): self._check_if_protected() // This returns None Object self._tweet = find_objects(self._raw, "__typename", ["Tweet", "TweetWithVisibilityResults"], recursive=False) // Runs error to call .get on a None value if self._tweet.get('tweet'): self._tweet = self._tweet['tweet']

@mahrtayyab
Copy link
Owner

Please do update to latest version

@Tyviebrock
Copy link

image
Can confirm issue is now fixed in version 2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants