meetar
meetar

Reputation: 7611

Soundcloud API returns 401 error on server-side Python authentication

Trying to authenticate in Python to test a registered app, as per "Authenticating without the SoundCloud Connect Screen": http://developers.soundcloud.com/docs/api/guide#user-credentials

import soundcloud

# create client object with app and user credentials
client = soundcloud.Client(client_id='YOUR_CLIENT_ID',
                           client_secret='YOUR_CLIENT_SECRET',
                           username='YOUR_USERNAME',
                           password='YOUR_PASSWORD')

The password='YOUR_PASSWORD' line throws an error:

File "/usr/local/lib/python2.7/dist-packages/soundcloud/client.py", line 41, in __init__
    self._credentials_flow()
File "/usr/local/lib/python2.7/dist-packages/soundcloud/client.py", line 112, in _credentials_flow
    make_request('post', url, options))
File "/usr/local/lib/python2.7/dist-packages/soundcloud/resource.py", line 62, in wrapped_resource
    setattr(result, attr, getattr(response, attr))
AttributeError: 'Response' object has no attribute 'error'

If I wrap it in a try:, I get:

Error: 401 Client Error: None, Status Code: 401

I've triple-checked the client_id and client_secret, I can log in using the same credentials on the website, and I've tried both 'username' and '[email protected]' formats in the code. Any ideas?

[Edit:] For the record, both 'username' and '[email protected]' formats work.

Upvotes: 1

Views: 943

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121644

You'll have to downgrade your requests library to version 0.14.2.

The soundcloud API python library wraps the requests.models.Response object, and with the refactor made for version 1.0.0, the .error attribute was removed. soundcloud however still expects it to be there.

I recommend you use a virtualenv to install libraries. You could manually remove the requests library from that virtualenv, or use pip to downgrade it:

pip install -I requests==0.14.2

You may want to report this issue to the soundcloud-python code project so that they can either fix their setup.py dependency or fix the library to work with requests 1.0.0 or newer.

Upvotes: 3

Related Questions