rjw57 / yt

Experiments with the YouTube API
MIT License
83 stars 25 forks source link

Pressing arrow keys (and many others) in search causes yt to crash #42

Open dotslashcow opened 10 years ago

dotslashcow commented 10 years ago

When you press any unexpected character while the search bar is open, yt immediately crashes. I can reliably reproduce this with all arrow keys, delete, home, end, insert, tab, all function keys, basically anything that isn't in what appears to be yt's array of expected characters. In such cases, yt crashes with the following error:

Traceback (most recent call last):
  File "/usr/bin/yt", line 439, in <module>
    main()
  File "/usr/bin/yt", line 18, in main
    ui.run()
  File "/usr/bin/yt", line 55, in run
    curses.wrapper(self._curses_main)
  File "/usr/lib/python2.7/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/bin/yt", line 102, in _curses_main
    self._run_pager()
  File "/usr/bin/yt", line 250, in _run_pager
    s = self._input('search')
  File "/usr/bin/yt", line 140, in _input
    s += chr(c)
ValueError: chr() arg not in range(256)

Additionally, pressing Enter or Backspace when the search string is empty causes yt to crash immediately with the following error:

Traceback (most recent call last):
  File "/usr/bin/yt", line 439, in <module>
    main()
  File "/usr/bin/yt", line 18, in main
    ui.run()
  File "/usr/bin/yt", line 55, in run
    curses.wrapper(self._curses_main)
  File "/usr/lib/python2.7/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/bin/yt", line 102, in _curses_main
    self._run_pager()
  File "/usr/bin/yt", line 250, in _run_pager
    s = self._input('search')
  File "/usr/bin/yt", line 143, in _input
    input_win.addstr(0, 0, ('%s' % (get_query_result(s),)).encode(self._code))
  File "/usr/bin/yt", line 430, in get_query_result
    result = json.load(urllib2.urlopen('%s?%s' % (url, urllib.urlencode(query))))
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 410, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 448, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request

Thank you, and have a nice day!