beetbox / beets

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

MusicBrainz won't connect (SSL: CERTIFICATE_VERIFY_FAILED) #3965

Closed 2V3EvG4LMJFdRe closed 3 years ago

2V3EvG4LMJFdRe commented 3 years ago

beets won't connect to MusicBrainz. discogs, fetchart, other things connect, but not this.

Problem

Running this command in verbose (-vv) mode:

beet -vv import /Volumes/Expansion-1/Media/Audio/

Led to this problem:

Searching for MusicBrainz releases with: {'release': '14番目の月', 'arid': '89ad4ac3-39f7-470e-963a-56509c546377', 'tracks': '10'}
Sending event: import_task_created
ignoring b'.DS_Store' due to ignore rule b'.*'
Sending event: import_task_created
ignoring b'.DS_Store' due to ignore rule b'.*'
Sending event: import_task_created
ignoring b'.DS_Store' due to ignore rule b'.*'
Sending event: import_task_created
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1016, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 956, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1392, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/musicbrainzngs/musicbrainz.py", line 497, in _safe_read
    f = opener.open(req)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1360, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/beets/autotag/mb.py", line 508, in match_album
    limit=config['musicbrainz']['searchlimit'].get(int), **criteria)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/musicbrainzngs/musicbrainz.py", line 978, in search_releases
    return _do_mb_search('release', query, fields, limit, offset, strict)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/musicbrainzngs/musicbrainz.py", line 782, in _do_mb_search
    return _do_mb_query(entity, '', [], params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/musicbrainzngs/musicbrainz.py", line 728, in _do_mb_query
    return _mb_request(path, 'GET', auth_required, args=args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/musicbrainzngs/musicbrainz.py", line 417, in __call__
    return self.fun(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/musicbrainzngs/musicbrainz.py", line 690, in _mb_request
    resp = _safe_read(opener, req, body)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/musicbrainzngs/musicbrainz.py", line 525, in _safe_read
    raise NetworkError(cause=exc)
musicbrainzngs.musicbrainz.NetworkError: caused by: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)>

Error: MusicBrainz not reachable in release search with query {'release': '14番目の月', 'arid': '89ad4ac3-39f7-470e-963a-56509c546377', 'tracks': '10'}

Setup

My configuration (output of beet config) is:

directory: /Volumes/Expansion-1/Media/Audio/

plugins: convert discogs duplicates fetchart embedart lyrics missing zero

autotag: yes

art_filename: cover

clutter: .pdf .bmp .png .jpg .jpef .tif .gif .sfv .nfo .m3u .log .DS_Store Thumbs.DB Thumbs.db

original_date: yes

languages: en

va_name: Various

ignored_media: .vob .mp4 .mkv .avi .ts .pdf .cbz .cbr

import:
    copy: no
    write: yes
    move: yes

paths:
    default: $albumartist/$album%aunique{albumartist album, tracktotal year label,()}/$track. $title
    comp: Various/$album%aunique{albumartist album, tracktotal year label,()}/$track. $title
    albumartist:various artists: Various/$album%aunique{albumartist album, tracktotal year label,()}/$track. $title
replace:
    '[\\/]': _
    '^\.': _
    '[\x00-\x1f]': _
    '[<>:"\?\*\|]': _
    '\.$': _
    '\s+$': ''
    '^\s+': ''
    '^-': _
convert:
    tmpdir: /Volumes/Expansion-1/Media/Audio/
    auto: yes
    delete_originals: yes
    never_convert_lossy_files: yes
    format: mp3
    mp3:
      command: ffmpeg -i $source -q:a 0 -map_metadata 0 $dest
      extension: mp3
discogs:
    user_token: redacted
duplicates:
    album: yes
    move: /Users/redacted/Downloads/
fetchart:
    auto: yes
    sources: fanarttv itunes amazon coverart albumart google
    fanarttv_key: redacted
    google_API_key: redacted
embedart: 
    auto: yes
    maxwidth: 1000
lyrics:
    auto: yes
    force: yes
    sources: genius musixmatch lyricwiki google
    google_API_key: redacted
    fallback: ''
    import.write: yes
chroma:
    auto: no
zero:
    auto: yes
    update_database: true
    keep_fields:        
        - artist
        - title
        - album
        - year
        - composer
        - albumartist
        - track
        - tracktotal
        - disc
        - disctotal
        - label
        - acoustid_fingerprint
        - acoustid_id
        - albumtype
        - lyrics
        - unsyncedlyrics
        - images
        - rating
        - first played
        - last played
        - play count

https://github.com/beetbox/beets/issues/3052#issuecomment-430325851 didn't work. It was already installed, and the error persists.

wisp3rwind commented 3 years ago

I lack the knowledge to comment on the SSL problem directly; but looking at the log ("/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/beets/autotag/mb.py"), you're running beets on Python 3.7, not 2.7. So you'd need to apply any fix from the linked thread to Python 3.7, too.

2V3EvG4LMJFdRe commented 3 years ago

Thanks for the clue, I'll see what I can do about it. It's a complete mess to manage python on mac if you don't nail it from the beginning. I may have 2, 3 installations by now.

2V3EvG4LMJFdRe commented 3 years ago

Yeah, I don't know. The fix to this in the linked comment and elsewhere is just installs certifi, but:

$ pip3 install certifi
Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (2021.5.30)
WARNING: You are using pip version 21.1.1; however, version 21.1.2 is available.
You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -m pip install --upgrade pip' command.
$ pip install certifi
Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (2020.12.5)

To be clear, beets connects to Discogs just fine. So it could just be MusicBrainz, but since I see no one else with the issue...

Any dirty hacks around this? Disabling the need for certificates at my own risk should work, but I'm not sure what to modify in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py or maybe /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/beets/autotag/mb.py to bypass it.

I may reinstall Python3, but I'm equally lost there to be honest.

wisp3rwind commented 3 years ago

A quick search revealed a few relevant stackoverflow pages:

https://stackoverflow.com/questions/35569042/ssl-certificate-verify-failed-with-python3 https://stackoverflow.com/questions/51925384/unable-to-get-local-issuer-certificate-when-using-requests-in-python

You might find a hint there.

2V3EvG4LMJFdRe commented 3 years ago

Yeah, I've gone through all those threads already, more or less tried everything suggested. The thing I'm going to do next is to uninstall Python and reinstall via the package from the official site. Should be less problematic than beets. I'll come back with how that goes when I get to it.

wisp3rwind commented 3 years ago

Moving this to Discussions, as this is most likely not a bug with beets.