soundcloud-lib icon indicating copy to clipboard operation
soundcloud-lib copied to clipboard

Library should give a meaningful error when tracks are not available due to geography

Open bauerj opened this issue 6 years ago • 6 comments

While trying to run the example from the README:

from sclib import SoundcloudAPI, Track, Playlist 

api = SoundcloudAPI()  # never pass a Soundcloud client ID that did not come from this library

track = api.resolve('https://soundcloud.com/itsmeneedle/sunday-morning')

assert type(track) is Track

filename = f'./{track.artist} - {track.title}.mp3'

with open(filename, 'wb+') as fp:
    track.write_mp3_to(fp)

I get this exception:

<class 'urllib.error.HTTPError'> HTTP Error 401: Unauthorized 
File object passed to "write_mp3_to" must be opened in read/write binary ("wb+") mode 
'bool' object is not subscriptable
Traceback (most recent call last): 
  File "app.py", line 12, in <module>
    track.write_mp3_to(fp) 
  File "/usr/local/lib/python3.6/dist-packages/sclib/sync.py", line 172, in write_mp3_to
    raise e
  File "/usr/local/lib/python3.6/dist-packages/sclib/sync.py", line 158, in write_mp3_to
    stream_url = self.get_stream_url() 
  File "/usr/local/lib/python3.6/dist-packages/sclib/sync.py", line 183, in get_stream_url
    )['http_mp3_128_url']
TypeError: 'bool' object is not subscriptable

bauerj avatar May 09 '19 08:05 bauerj

Thanks for reporting! This same issue causes sporadic automated test failures. Usually, I just manually run the test again and it passes. You should be able to rerun the example and have it work correctly.

If you can consistently reproduce this error, please let me know how. Otherwise, I'll have to look into building in some retry-on-error mechanism.

3jackdaws avatar May 10 '19 04:05 3jackdaws

The error occured in 10/10 tries today. Does it still work for you?

bauerj avatar May 10 '19 15:05 bauerj

The example works for me on Centos and MacOS.

Can you provide your:

  • OS
  • Python version
  • soundcloud-lib version (pip show soundcloud-lib)
  • The exact code you are using

This will help me debug. Thanks!

3jackdaws avatar May 11 '19 15:05 3jackdaws

Sure!

OS

Ubuntu 18.04.2 LTS

Python Version

Python 3.6.7

soundcloud-lib version

$ python3 -m pip show soundcloud-lib
Name: soundcloud-lib 
Version: 0.4.1
Summary: Python Soundcloud API
Home-page: https://github.com/3jackdaws/soundcloud-lib
Author: Ian Murphy
Author-email: [email protected] 
License: MIT
Location: /usr/local/lib/python3.6/dist-packages
Requires: bs4, aiohttp, mutagen
$ python3 -m pip freeze 
aiohttp==3.5.4 
asn1crypto==0.24.0
async-timeout==3.0.1
attrs==17.4.0
Automat==0.6.0 
beautifulsoup4==4.7.1
bs4==0.0.1
certifi==2018.1.18
chardet==3.0.4
click==6.7
colorama==0.3.7
command-not-found==0.3
configobj==5.0.6
constantly==15.1.0
cryptography==2.1.4
distro-info===0.18ubuntu0.18.04.1
fail2ban==0.10.2
httplib2==0.9.2
hyperlink==17.3.1
idna==2.6
idna-ssl==1.1.0
incremental==16.10.1
iotop==0.6
keyring==10.6.0
keyrings.alt==3.0
language-selector==0.1
multidict==4.5.2
mutagen==1.42.0
netifaces==0.10.4
PAM==0.4.2
pyasn1==0.4.2
pyasn1-modules==0.2.1
pycrypto==2.6.1
pycurl==7.43.0.1
pygobject==3.26.1
pyinotify==0.9.6
pyOpenSSL==17.5.0
pyserial==3.4
python-apt==1.6.3+ubuntu1
python-debian==0.1.32
pyxdg==0.25
PyYAML==3.12
requests==2.18.4
requests-unixsocket==0.1.5
SecretStorage==2.3.1
service-identity==16.0.0
six==1.11.0
soundcloud-lib==0.4.1
soupsieve==1.9.1
ssh-import-id==5.7
systemd-python==234
Twisted==17.9.0
typing-extensions==3.7.2
ufw==0.36
unattended-upgrades==0.1
urllib3==1.22
yarl==1.3.0
zope.interface==4.3.2

The exact code I am using

from sclib import SoundcloudAPI, Track, Playlist

api = SoundcloudAPI()  # never pass a Soundcloud client ID that did not come from this library 

track = api.resolve('https://soundcloud.com/itsmeneedle/sunday-morning')

assert type(track) is Track

filename = f'./{track.artist} - {track.title}.mp3'

with open(filename, 'wb+') as fp:
    track.write_mp3_to(fp)

bauerj avatar May 13 '19 09:05 bauerj

@3jackdaws It's a 401 and maybe it's due to the track only being accessible at some locations on this planet we are living on: image

IMHO either there is a workaround with the JSON API you are using for this package or a proper error message should be returned.

Nachtalb avatar May 13 '19 20:05 Nachtalb

@Nachtalb I had considered that since @bauerj is from Germany. There are a couple of coding improvements that should be made to the library and more readable errors is one of them.

I will leave this bug open until the library is updated to throw a more meaningful exception.

3jackdaws avatar May 13 '19 23:05 3jackdaws