Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: AudioSegment.from_mp3(mp3_audio) in Mac (Solved) #62

Closed
jxlil opened this issue Nov 11, 2023 · 0 comments
Closed

Bug: AudioSegment.from_mp3(mp3_audio) in Mac (Solved) #62

jxlil opened this issue Nov 11, 2023 · 0 comments

Comments

@jxlil
Copy link

jxlil commented Nov 11, 2023

Hello

I was receiving the following error when trying to solve captcha by audio in Macos (I leave the solution in case someone else gets the same error):

Traceback (most recent call last):
  File "/Users/jxlil/captcha/test.py", line 10, in <module>
    token = solver.solve_recaptcha(wait=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jxlil/captcha/.venv/lib/python3.11/site-packages/playwright_recaptcha/recaptchav2/sync_solver.py", line 606, in solve_recaptcha
    self._solve_audio_challenge(recaptcha_box)
  File "/Users/jxlil/captcha/.venv/lib/python3.11/site-packages/playwright_recaptcha/recaptchav2/sync_solver.py", line 464, in _solve_audio_challenge
    text = self._convert_audio_to_text(url)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jxlil/captcha/.venv/lib/python3.11/site-packages/playwright_recaptcha/recaptchav2/sync_solver.py", line 274, in _convert_audio_to_text
    audio = AudioSegment.from_mp3(mp3_audio)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jxlil/captcha/.venv/lib/python3.11/site-packages/pydub/audio_segment.py", line 796, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jxlil/captcha/.venv/lib/python3.11/site-packages/pydub/audio_segment.py", line 728, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jxlil/captcha/.venv/lib/python3.11/site-packages/pydub/utils.py", line 279, in mediainfo_json
    info = json.loads(output)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Future exception was never retrieved
future: <Future finished exception=Error('Connection closed')>
playwright._impl._api_types.Error: Connection closed

The error is generated in the pydub (pydub/utils.py) library, in this part:

def mediainfo_json(filepath, read_ahead_limit=-1):
    ...
    command = [prober, '-of', 'json'] + command_args
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
    output, stderr = res.communicate(input=stdin_data)
    output = output.decode("utf-8", 'ignore')
    stderr = stderr.decode("utf-8", 'ignore')

    --> info = json.loads(output)

This is because output is an empty string and it is supposed to be a JSON formatted string.


Solution

Although the problem seems to be in one of the libraries, in my case it was due to ffmpeg. Reinstalling it as follows solved the problem:

brew uninstall librist --ignore-dependencies
brew uninstall mbedtls --ignore-dependencies
brew reinstall ffmpeg
@jxlil jxlil closed this as completed Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant