beetbox / beets

music library manager and MusicBrainz tagger
http://beets.io/
MIT License
12.77k stars 1.82k forks source link

discogs plugin traceback error #1656

Closed iamgregg closed 8 years ago

iamgregg commented 8 years ago

I'm getting the following traceback error when trying to use the discogs plugin:

Traceback (most recent call last):
  File "/usr/local/bin/beet", line 9, in <module>
    load_entry_point('beets==1.3.15', 'console_scripts', 'beet')()
  File "/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py", line 1163, in main
    _raw_main(args)
  File "/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py", line 1153, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/local/lib/python2.7/dist-packages/beets/ui/commands.py", line 875, in import_func
    import_files(lib, paths, query)
  File "/usr/local/lib/python2.7/dist-packages/beets/ui/commands.py", line 852, in import_files
    session.run()
  File "/usr/local/lib/python2.7/dist-packages/beets/importer.py", line 313, in run
    plugins.send('import_begin', session=self)
  File "/usr/local/lib/python2.7/dist-packages/beets/plugins.py", line 458, in send
    result = handler(**arguments)
  File "/usr/local/lib/python2.7/dist-packages/beets/plugins.py", line 123, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/beetsplug/discogs.py", line 77, in setup
    token, secret = self.authenticate(c_key, c_secret)
  File "/usr/local/lib/python2.7/dist-packages/beetsplug/discogs.py", line 100, in authenticate
    _, _, url = auth_client.get_authorize_url()
  File "/usr/local/lib/python2.7/dist-packages/discogs_client/client.py", line 61, in get_authorize_url
    content, status_code = self._fetcher.fetch(self, 'POST', self._request_token_url, data=postdata, headers=params)
  File "/usr/local/lib/python2.7/dist-packages/discogs_client/fetchers.py", line 95, in fetch
    resp = request(method, uri, headers=headers, data=body)
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py", line 559, in urlopen
    body=body, headers=headers)
  File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py", line 353, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python2.7/httplib.py", line 966, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1000, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 962, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 826, in _send_output
    self.send(message_body)
  File "/usr/lib/python2.7/httplib.py", line 798, in send
    self.sock.sendall(data)
  File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 216, in sendall
    data = memoryview(data)
TypeError: cannot make memory view because object does not have the buffer interface

I have tried updating both beets and discogs-client using pip, but it still throws the same error.

My config is quite simple as I'm new to beets:

directory: /home/owner/Music
library: /home/owner/.config/beets/library.blb
plugins: fetchart discogs
replace:
    '[\\/]': _
    '^\.': _
    '[\x00-\x1f]': _
    '[<>:"\?\*\|]': _
    '\.$': _
    '\s+$': ''
    '^\s+': ''
threaded: yes

fetchart:
  cover_names: front cover art album folder
  maxwidth: 500

import:
    write: yes
    copy: yes
    resume: ask
    log: beetslog.txt

paths:
    default: $albumartist/$album%aunique{}/$track $title
    singleton: Non-Album/$artist/$title
    comp: Compilations/$album%aunique{}/$track $title
    albumtype:soundtrack: Soundtracks/$album/$track $title
sampsyo commented 8 years ago

Very strange indeed. I can't seem to reproduce this on my end:

$ rm -f ~/.config/beets/discogs_token.json
$ beet import [...]
To authenticate with Discogs, visit:
https://www.discogs.com/oauth/authorize?oauth_token=[...]
Enter the code:

This is on discogs-client==2.1.0 and requests==2.8.1, with Python 2.7.10 and the latest beets source.

I am, unfortunately, at a loss regarding what might be different about our setups. Could something be wrong with PyOpenSSL on your machine?

iamgregg commented 8 years ago

Python 2.7.4 beets 1.3.15 discogs-client 2.1.0 requests 2.8.1

This appears to be a bug with urllib:

Relevant links:

https://github.com/kennethreitz/requests/issues/2818 https://github.com/shazow/urllib3/pull/719 https://github.com/kennethreitz/requests/pull/2821

Some relevant quotes:

To be clear, the error you're encountering is a known bug in urllib3 that has been fixed (see shazow/urllib3#719). However, that fix will not be pulled into the released version of requests until urllib3 ships a new release and then requests ships 2.9.0. Until such time, you could apply the diff from the linked patch to your installation or, alternatively, simply encode the data yourself.

And also

I feel certain that we've fixed this already, perhaps in 3.0.0?

And a quick look shows we fixed it on July 18th: ea1cbb3

I don't see discussion in the bug about why we didn't propose that against master though (although parts of it are backwards incompatible).

I'm +1 on fixing this and this looks like a good, simple, probably backwards compatible change.

It appears I'm waiting for a requests release that fixes an incompatibility issue.

sampsyo commented 8 years ago

Thanks for digging into the issue—that's disappointing. I'm flying blind here, but I'm going to try making sure that we pass all data to the client as bytestrings. That might work around the problem for now.

sampsyo commented 8 years ago

Sadly, I had to revert my "fix" as it was causing other crashes inside the discogs library (c.f. #1669). :cry:

iamgregg commented 8 years ago

Reporting in that the recent urllib3 and requests releases have fixed this issue.

sampsyo commented 8 years ago

Fantastic news. Thanks for checking back in, @iamgregg.