michael-lazar / rtv

Browse Reddit from your terminal
MIT License
4.64k stars 274 forks source link

crash "AttributeError: can't set attribute" #665

Closed ghost closed 5 years ago

ghost commented 5 years ago

Describe the bug Simply launched for the first time, not logged in, hit right arrow on an arbitrary article, and it crashed:

8. Reasons Trump Is A Bad President
 https://i.imgur.com/OFxb3sN.jpg
 37068 pts • 18hr - 2247 comments ✪
 AXXXXXXXXA /r/PoliticalHumor
Traceback (most recent call last):mpt [u]Login [o]Open [c]Post [a/z]Vote                                                                    
  File "/usr/bin/rtv", line 11, in <module>
    load_entry_point('rtv==1.14.1', 'console_scripts', 'rtv')()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 561, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2291, in load
    return self.resolve()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2297, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3/dist-packages/rtv/__main__.py", line 169, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/rtv/__main__.py", line 152, in main
    page.loop()
  File "/usr/lib/python3/dist-packages/rtv/page.py", line 78, in loop
    self.controller.trigger(ch)
  File "/usr/lib/python3/dist-packages/rtv/objects.py", line 595, in trigger
    return func(self.instance, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/rtv/subreddit_page.py", line 107, in open_submission
    self.reddit, self.term, self.config, self.oauth, url=url)
  File "/usr/lib/python3/dist-packages/rtv/submission_page.py", line 30, in __init__
    max_comment_cols=config['max_comment_cols'])
  File "/usr/lib/python3/dist-packages/rtv/content.py", line 321, in from_url
    submission = reddit.get_submission(url, comment_sort=order)
  File "/usr/lib/python3/dist-packages/praw/__init__.py", line 1042, in get_submission
    params=params)  
  File "<decorator-gen-191>", line 2, in from_url
  File "/usr/lib/python3/dist-packages/praw/decorators.py", line 268, in wrap
    return function(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/praw/objects.py", line 1111, in from_url
    response = reddit_session.request_json(url, params=params)
  File "<decorator-gen-8>", line 2, in request_json
  File "/usr/lib/python3/dist-packages/praw/decorators.py", line 113, in raise_api_exceptions
    return_value = function(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/praw/__init__.py", line 621, in request_json
    data = json.loads(response, object_hook=hook)
  File "/usr/lib/python3.5/json/__init__.py", line 332, in loads
    return cls(**kw).decode(s)
  File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.5/json/decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
  File "/usr/lib/python3/dist-packages/praw/__init__.py", line 479, in _json_reddit_objecter
    return object_class.from_api_response(self, json_data['data'])
  File "/usr/lib/python3/dist-packages/praw/objects.py", line 56, in from_api_response
    return cls(reddit_session, json_dict=json_dict)
  File "/usr/lib/python3/dist-packages/praw/objects.py", line 613, in __init__
    underscore_names=['replies'])
  File "/usr/lib/python3/dist-packages/praw/objects.py", line 71, in __init__
    self._has_fetched = self._populate(json_dict, fetch)
  File "/usr/lib/python3/dist-packages/praw/objects.py", line 171, in _populate
    setattr(self, name, value)
  File "/usr/lib/python3/dist-packages/praw/objects.py", line 119, in __setattr__
    object.__setattr__(self, name, value)
AttributeError: can't set attribute

Describe your environment I installed on Debian stretch this way:

$ sudo aptitude install rtv

Then I ran:

firejail --net=none rtv --help

which lead me to run:

torsocks rtv --copy-config

Made no cfg changes. Ran this to launch a normal session for the first time:

firejail --net=tornet --dns="$mydns" --whitelist="${my_rtv_cfg_file%/*}" rtv --config "$my_rtv_cfg_file"

FYI, firejail --net=tornet.. sandboxes the app and forces all network connections through a Tor middlebox. The --whitelist=* restricts rtf to only getting write permission in the directory holding the config file. The same crash happens even if I remove the --whitelist=* parameter to loosen permissions, so that's not related.

michael-lazar commented 5 years ago

Thanks for the detailed bug report!

This is your problem: rtv==1.14.1. The Debian stable package is sadly out of date and Reddit has since made breaking changes to their API which broke old versions of rtv.

https://repology.org/project/rtv/packages

ghost commented 5 years ago

Thanks for the quick reply. I guess the only question then is whether the stack trace can be replaced with a message that says "error: your version is no longer aligned with the API". It was able to render the landing page but broke when an article was selected.

michael-lazar commented 5 years ago

Normally, bad HTTP responses like 4xx and 5xx are handled more gracefully. This was a special case because reddit started returning a new field that conflicted with one of the built-in methods in praw and inadvertently broke the library in an unexpected way. Without swallowing all unknown exceptions there's not much that could have been done.

ghost commented 5 years ago

The error msg "attribute error" had me thinking that it was an attribute in the config file that was a problem, because knowing the Debian is often behind and the fact that --copy-config may be grabbing the latest config I thought it was a misalignment. If it had said "API attribute error" that would have been more clear. I'm not sure if that would have the same complication you mention.

(edit) Looks like this bug has kept rtv in an unusable state for over a year: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=884632

It was marked as fixed a month ago but it's still not. Any idea why Stretch still has an old version @noahfx?

The backports version of rtv is also 1.14.1.

noahfx commented 5 years ago

Hi @libBletchley

Currently Stretch has an old version, the fix never got into stretch neither backports, sorry about this. Since Stretch is in its final cycle, I will not update the package at this time.

I have prepared a new package working on stretch, you can download it here: https://people.debian.org/~josue/debian/rtv/rtv_1.25.1+dfsg-1+bpo_all.deb

noahfx commented 5 years ago

I have uploaded the fix to the Stretch backports: https://ftp-master.debian.org/new/rtv_1.25.1+dfsg-1~bpo9+1.html Currently it is in an approval queue, should be accepted in the next days.

Sorry for the inconvenience

michael-lazar commented 5 years ago

Thanks!

ghost commented 5 years ago

Thank you! It's available in the backports now.