hfaran / slack-export-viewer

A Slack Export archive viewer that allows you to easily view and share your Slack team's export
https://pypi.python.org/pypi/slack-export-viewer
MIT License
966 stars 193 forks source link

slack-export-viewer fails at flask\__init__.py", line 60, in __getattr__ raise AttributeError(name) #171

Closed DavidRLovell closed 1 year ago

DavidRLovell commented 1 year ago

Apologies in advance: I'm no pythonista: the issue may be obvious, but not to me.

If I install and invoke slack-export-viewer from my Anaconda Powershell Prompt window, things fail as follows. Any advice, workarounds etc, would be greatly appreciated!

(base) PS C:\Users\me\OneDrive - Queensland University of Technology\Slack> slack-export-viewer -z '.\exports\My Slack export Jul 20 2023 - Oct 18 2023.zip'
C:\Users\me\AppData\Local\Temp\_slackviewer\1c11cbcf1c3099b08cfe1766d575e9b432e43ed2 already exists
Traceback (most recent call last):
  File "C:\Users\me\AppData\Local\anaconda3\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\me\AppData\Local\anaconda3\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\me\AppData\Local\anaconda3\Scripts\slack-export-viewer.exe\__main__.py", line 7, in <module>
  File "C:\Users\me\AppData\Local\anaconda3\lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\me\AppData\Local\anaconda3\lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "C:\Users\me\AppData\Local\anaconda3\lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\me\AppData\Local\anaconda3\lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\me\AppData\Local\anaconda3\lib\site-packages\slackviewer\main.py", line 61, in main
    configure_app(app, archive, channels, no_sidebar, no_external_references, debug)
  File "C:\Users\me\AppData\Local\anaconda3\lib\site-packages\slackviewer\main.py", line 23, in configure_app
    top = flask._app_ctx_stack
  File "C:\Users\me\AppData\Local\anaconda3\lib\site-packages\flask\__init__.py", line 60, in __getattr__
    raise AttributeError(name)
AttributeError: _app_ctx_stack
HiIAmTzeKean commented 1 year ago

I had the same error try to change your package version, then run the program again

pip3 install Werkzeug==2.0.0
pip3 install Flask==2.0.0
timbaileyjones commented 1 year ago

Thank you, @HiIAmTzeKean ... Same problem, same solution.

timbaileyjones commented 1 year ago

I made a PR #172 to pull the latest 2.x versions of those two libraries, not just 2.0.0.

DavidRLovell commented 1 year ago

Dear @HiIAmTzeKean, I'm very grateful to you for helping me. This does the trick, though I do get some warnings:

(base) PS C:\Users\me\OneDrive - Queensland University of Technology\Slack> pip3 install Werkzeug==2.0.0
Collecting Werkzeug==2.0.0
  Downloading Werkzeug-2.0.0-py3-none-any.whl (288 kB)
     ---------------------------------------- 288.1/288.1 kB 9.0 MB/s eta 0:00:00
Installing collected packages: Werkzeug
  Attempting uninstall: Werkzeug
    Found existing installation: Werkzeug 3.0.0
    Uninstalling Werkzeug-3.0.0:
      Successfully uninstalled Werkzeug-3.0.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
flask 3.0.0 requires Werkzeug>=3.0.0, but you have werkzeug 2.0.0 which is incompatible.
Successfully installed Werkzeug-2.0.0
DavidRLovell commented 1 year ago

Dear @HiIAmTzeKean and @timbaileyjones, Again, thanks for your help. If you have the time and inclincation, could you explain to me (as a python novice) how I could have figured out the solution you provided @HiIAmTzeKean? Would I have had to have known info about the internals of slack-export-viewer, or is the solution obvious to experienced python programmers? With gratitude! David

HiIAmTzeKean commented 1 year ago

I can't exactly give you a concrete answer as to why 2.0.0 works as I did a trial an error when I was debugging. But based on the error message it seems like there was a function call that was not recognised/ misbehaving. I do not know the internal workings of the code myself as I am an end user, but searching up the error message will yield some results that regarding flask dependencies.

Hope this helps!

hfaran commented 1 year ago

Werkzeug and Flask have been pinned to <3.0.0 in the latest release, so this shouldn't happen anymore

timbaileyjones commented 1 year ago

When software has a revision change, as both of these libaries did, from 2.x to 3.0 in this case, it is called a MAJOR release. If it had been a change in the second number, say 2.1 to 2.2, it is called a MINOR release. If it had been a change in the third number, say 2.1.1 to 2.1.2, that is called a PATCH release.

There are general expectations communicated from the authors, by which part of the version number is updated. Read more fully about it here. This idea is called Semantic Versioning.

One of those expectations is that you can EXPECT breaking changes with major releases. The original requirements.txt file didn't specify a particular version at all, and pip grabs the latest version (which in this case was 3.x). So both @HiIAmTzeKean's fix and my PR just pin those two libraries to versions that are in the 2.x range. He specified the very first release in the 2.x series, which is 2.0.0. My PR was the same idea, but mine will pull the latest 2.x, not the oldest. (i.e the latest that is less than 3.0.0).

Also, more experienced pythonistas have experienced similar breakage with those two particular libraries going from 2 to 3, and may have just known instinctively that this was the problem.

So part of this lesson is how Semantic Versioning works. The second part is how important it is to properly pin your project's requirements, to at least the right MAJOR version.

The third lesson is how quickly this open source can work to solve problems.

Problem solved! I wrote about the whole journey here and you guys are part of it!

DavidRLovell commented 1 year ago

Thanks again @timbaileyjones, @HiIAmTzeKean and, of course @hfaran.

more experienced pythonistas have experienced similar breakage with those two particular libraries going from 2 to 3, and may have just known instinctively that this was the problem.

...is, I think, the case. since the original error message said nothing about package versions. All the best! David