firecat53 / urlscan

Mutt and terminal url selector (similar to urlview)
GNU General Public License v2.0
214 stars 38 forks source link

urlscan crashes on url open #69

Closed lgaggini closed 6 years ago

lgaggini commented 6 years ago

Hi,

urlscan starts to crash on url open with the follow stacktrace:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/urwid/main_loop.py", line 376, in _run
    self.start()
  File "/usr/lib/python3.7/site-packages/urwid/main_loop.py", line 344, in start
    "Screen {0!r} doesn't support external event loops")
urwid.main_loop.CantUseExternalLoop: Screen {0!r} doesn't support external event loops

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/urlscan", line 187, in <module>
    main()
  File "/usr/bin/urlscan", line 178, in main
    tui.main()
  File "/usr/lib/python3.7/site-packages/urlscan/urlchoose.py", line 123, in main
    self.loop.run()
  File "/usr/lib/python3.7/site-packages/urwid/main_loop.py", line 286, in run
    self._run()
  File "/usr/lib/python3.7/site-packages/urwid/main_loop.py", line 379, in _run
    return self._run_screen_event_loop()
  File "/usr/lib/python3.7/site-packages/urwid/main_loop.py", line 447, in _run_screen_event_loop
    self.process_input(keys)
  File "/usr/lib/python3.7/site-packages/urwid/main_loop.py", line 511, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/usr/lib/python3.7/site-packages/urwid/container.py", line 1131, in keypress
    return self.body.keypress( (maxcol, remaining), key )                                                                                                                                                          
  File "/usr/lib/python3.7/site-packages/urwid/listbox.py", line 999, in keypress                                                                                                                                  
    key = focus_widget.keypress((maxcol,),key)                                                                                                                                                                     
  File "/usr/lib/python3.7/site-packages/urwid/container.py", line 2271, in keypress
    key = w.keypress((mc,) + size[1:], key)
  File "/usr/lib/python3.7/site-packages/urwid/wimp.py", line 540, in keypress
    self._emit('click')
  File "/usr/lib/python3.7/site-packages/urwid/widget.py", line 460, in _emit
    signals.emit_signal(self, name, self, *args)
  File "/usr/lib/python3.7/site-packages/urwid/signals.py", line 265, in emit
    result |= self._call_callback(callback, user_arg, user_args, args)
  File "/usr/lib/python3.7/site-packages/urwid/signals.py", line 295, in _call_callback
    return bool(callback(*args_to_pass))
  File "/usr/lib/python3.7/site-packages/urlscan/urlchoose.py", line 296, in browse
    webbrowser.open(url)                                                                                                                                                                                           
  File "/usr/lib/python3.7/webbrowser.py", line 75, in open                                                                                                                                                        
    register_standard_browsers()                                                                                                                                                                                   
  File "/usr/lib/python3.7/webbrowser.py", line 567, in register_standard_browsers                                                                                                                                 
    cmd = _synthesize(cmdline, -1)                                                                                                                                                                                 
  File "/usr/lib/python3.7/webbrowser.py", line 116, in _synthesize
    register(browser, None, controller, update_tryorder)                                                                                                                                                           
TypeError: register() takes from 2 to 3 positional arguments but 4 were given

Keep up the good work :)

firecat53 commented 6 years ago

How did you install urwid? Is it through pypi or with the Arch package python-urwid? I originally had urlscan/urwid installed with pip --user and I saw the same error. When I installed python-urwid from the repositories, the issue went away. I'm guessing the pypi version of urwid might not be packaged correctly yet for python 3.7, but that's just a guess.

b0o commented 6 years ago

@firecat53 I'm having this issue as well. On Arch Linux, I've tried urlscan and urlscan-git from the AUR, and by installing urlscan with pip install --user urlscan, and all of them have this issue.

firecat53 commented 6 years ago

Have you explicitly installed python-urwid from the repositories? Make sure any local copies of urwid you installed via pip are removed also. That really is the only fix right now.

Edit: Did some more testing and I can't replicate your errors anymore, even with urwid installed via pip.

I did see this error shortly after python 3.7 was released. You really have to go in and make sure all instances of urwid and urlscan are uninstalled both system-wide and in your .local directories.

lgaggini commented 6 years ago

Thank you for your support. I have the first crash using python-urwind 2.0.1-2 from archlinux repo and both urlscan or urlscan-git from aur. Then I try a system wide install by pip but the same problem arises. In the end, to exclude my system wide problem I try a pip install in a virtualenv with no luck:

~
> mkvirtualenv -p /usr/bin/python3 urlscan
(urlscan) ~                                                                                                                                                                                                        
> python -V                                                                                                                                                                                                        
Python 3.7.0
(urlscan) ~  
> pip freeze                                                                                                                                                                                                       
(urlscan) ~                                                                                                                                                                                                        
>  
(urlscan) ~                                                                                                                                                                                                        
> pip --no-cache-dir install urlscan                                                                                                                                                                                
Collecting urlscan                                                                                                                                                                                                 
  Downloading https://files.pythonhosted.org/packages/6c/89/f86c747d293108bf07a3aa0d7e5fd69495a3895b684c0b5853789d91c257/urlscan-0.8.8-py2.py3-none-any.whl                                                        
Collecting urwid>=1.2.1 (from urlscan)                                                                                                                                                                             
  Downloading https://files.pythonhosted.org/packages/c7/90/415728875c230fafd13d118512bde3184d810d7bf798a631abc05fac09d0/urwid-2.0.1.tar.gz (604kB)                                                                
    100% |████████████████████████████████| 614kB 5.5MB/s                                                                                                                                                          
Installing collected packages: urwid, urlscan                                                                                                                                                                      
  Running setup.py install for urwid ... done                                                                                                                                                                      
Successfully installed urlscan-0.8.8 urwid-2.0.1
(urlscan) ~                                                                                                                                                                                                        
> pip freeze                                                                                                                                                                                                       
urlscan==0.8.8                                                                                                                                                                                                     
urwid==2.0.1
(urlscan) ~                                                                                                                                                                                                        
> which urlscan                                                                                                                                                                                                    
/home/lg/.virtualenvs/urlscan/bin/urlscan
(urlscan) ~                                                                                                                                                                                                        
> urlscan <path to email> + select url
Traceback (most recent call last):
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/main_loop.py", line 376, in _run
    self.start()
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/main_loop.py", line 344, in start                                                                                                          
    "Screen {0!r} doesn't support external event loops")                                                                                                                                                           
urwid.main_loop.CantUseExternalLoop: Screen {0!r} doesn't support external event loops                                                                                                                             

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/lg/.virtualenvs/urlscan/bin/urlscan", line 187, in <module>                                                                                                                                          
    main()                                                                                                                                                                                                         
  File "/home/lg/.virtualenvs/urlscan/bin/urlscan", line 178, in main                                                                                                                                              
    tui.main()                                                                                                                                                                                                     
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urlscan/urlchoose.py", line 123, in main                                                                                                         
    self.loop.run()                                                                                                                                                                                                
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/main_loop.py", line 286, in run                                                                                                            
    self._run()                                                                                                                                                                                                    
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/main_loop.py", line 379, in _run
    return self._run_screen_event_loop()                                                                                                                                                                           
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/main_loop.py", line 447, in _run_screen_event_loop                                                                                         
    self.process_input(keys)                                                                                                                                                                                       
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/main_loop.py", line 511, in process_input                                                                                                  
    k = self._topmost_widget.keypress(self.screen_size, k)                                                                                                                                                         
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/container.py", line 1131, in keypress
    return self.body.keypress( (maxcol, remaining), key )
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/listbox.py", line 999, in keypress
    key = focus_widget.keypress((maxcol,),key)
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/container.py", line 2271, in keypress
    key = w.keypress((mc,) + size[1:], key)
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/wimp.py", line 540, in keypress
    self._emit('click')
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/widget.py", line 460, in _emit
    signals.emit_signal(self, name, self, *args)
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/signals.py", line 265, in emit
    result |= self._call_callback(callback, user_arg, user_args, args)
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urwid/signals.py", line 295, in _call_callback
    return bool(callback(*args_to_pass))
  File "/home/lg/.virtualenvs/urlscan/lib/python3.7/site-packages/urlscan/urlchoose.py", line 296, in browse
    webbrowser.open(url)
  File "/usr/lib64/python3.7/webbrowser.py", line 75, in open
    register_standard_browsers()
  File "/usr/lib64/python3.7/webbrowser.py", line 567, in register_standard_browsers
    cmd = _synthesize(cmdline, -1)
  File "/usr/lib64/python3.7/webbrowser.py", line 116, in _synthesize
    register(browser, None, controller, update_tryorder)                                                                                                                                                           
TypeError: register() takes from 2 to 3 positional arguments but 4 were given                                                                                                                                      
firecat53 commented 6 years ago

Well...I was finally able to replicate this on a fresh Arch installation in a virtual machine. I have no idea what's different about my own system that's allowing it to work flawlessly! I also run a fully updated Archlinux with Python 3.7.

Hrm.

firecat53 commented 6 years ago

After some research, this appears to be a bug in the Python webbrowser module. It appears to have a fix merged, but I'm not sure when that will be released. For now, if you all could try the develop branch, I added a fix that hopefully will work around this bug.

lgaggini commented 6 years ago

Nice work, I can confirm the fix in the develop branch is working. :)

For anyone interested in the fix you can install the urlscan-git aur version using the develop branch modifying the PKGBUILD:


diff PKGBUILD PKGBUILD.original
14c14
< source=('git://github.com/firecat53/urlscan.git#branch=develop')
---
> source=('git://github.com/firecat53/urlscan.git')
firecat53 commented 6 years ago

Fix pushed to master and released to pypi with 0.8.9.