artyompetrov / AutoDefine_oxfordlearnersdictionaries

An add-on to Anki that auto-defines words and images.
GNU General Public License v2.0
17 stars 10 forks source link

Workaround "Remote end closed connection without response" error when downloading audio #21

Closed tvhong closed 11 months ago

tvhong commented 11 months ago

Oxford recently started aborting connections for audio downloads. Changing the User-agent header to "Mozilla/5.0" fixed the issue. I suspect Oxford just block listed 'mother animal' browers :-) .

Stack trace:

Traceback (most recent call last):
  File "/Users/vy/Library/Application Support/Anki2/addons21/570730390/autodefine.py", line 415, in get_data_with_exception_handling
    get_data(editor)
  File "/Users/vy/Library/Application Support/Anki2/addons21/570730390/autodefine.py", line 234, in get_data
    audio = get_audio(words_info)
  File "/Users/vy/Library/Application Support/Anki2/addons21/570730390/autodefine.py", line 359, in get_audio
    fill_audio_dict_prioritized(audio_dict, pronunciations, wordform)
  File "/Users/vy/Library/Application Support/Anki2/addons21/570730390/autodefine.py", line 389, in fill_audio_dict_prioritized
    response = req.get(audio_url, timeout=5, headers={'User-agent': 'mother animal'})
  File "requests.sessions", line 602, in get
  File "requests.sessions", line 589, in request
  File "requests.sessions", line 703, in send
  File "requests.adapters", line 501, in send
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
artyompetrov commented 11 months ago

Thanks for investigation of the problem!