1

尝试在 Python 中进行身份验证以测试已注册的应用程序,按照“在没有 SoundCloud 连接屏幕的情况下进行身份验证”: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')

password='YOUR_PASSWORD'行引发错误:

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'

如果我将它包装在 a 中try:,我会得到:

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

我已经三重检查了 client_id 和 client_secret,我可以在网站上使用相同的凭据登录,并且我在代码中尝试了“用户名”和“用户名@email.com”格式。有任何想法吗?

[编辑:] 作为记录,“用户名”和“用户名@email.com”格式都有效。

4

1 回答 1

3

您必须将requests库降级到 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.

于 2012-12-18T17:50:41.850 回答