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

Fixed read error when initializing bytes data in Python 3 #120

Merged
merged 1 commit into from
Jan 10, 2016

Conversation

shichao-an
Copy link
Contributor

The original code will throw AttributeError: 'bytes' object has no attribute 'read' when initializing pydub.AudioSegment with a bytes object in Python 3. Since your code indends to support Python 3 by using BytesIO (aliased into StringIO), pydub.AudioSegment should have accepted bytes data.

The problematic line of code is this:

data = data if isinstance(data, basestring) else data.read()

It only checks if data is basestring, which does not exist in Python 3. If data is of bytes in Python 3, it will go to else part and failed.

Since you didn't use six, I added an extra isinstance check here to make the code change as minimal as possible, though it may not be a good enough.

FYI, my code which complains about this is here, and the error output is:

$ ./run.py
Traceback (most recent call last):
  File "./run.py", line 5, in <module>
    main()
  File "/Users/shichao/Documents/projects/soundmeter/soundmeter/meter.py", line 315, in main
    m.start()
  File "/Users/shichao/Documents/projects/soundmeter/soundmeter/meter.py", line 126, in start
    segment = pydub.AudioSegment(data)
  File "/Users/shichao/envs/soundmeter3.4/lib/python3.4/site-packages/pydub/audio_segment.py", line 130, in __init__
    data = data if isinstance(data, basestring) else data.read()
AttributeError: 'bytes' object has no attribute 'read'

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

Successfully merging this pull request may close these issues.

2 participants