API authentication w/Python fails with latest requests library #17

Closed
meetar opened this Issue Dec 18, 2012 · 7 comments

Projects

None yet

7 participants

@meetar

When attempting to authenticate using the "Authenticating without the SoundCloud Connect Screen" method:

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

To fix, I had to downgrade my requests library to version 0.14.2.

As per http://stackoverflow.com/questions/13938275/soundcloud-api-returns-401-error-on-server-side-python-authentication :

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

@twobob

same here

[root@kindle soundcloud-python] nosetests --with-doctest

ERROR: Anything in the 400 or 500 range should raise an exception.

Traceback (most recent call last):
File "/mnt/us/usr/local/lib/python2.7/dist-packages/nose-1.1.2-py2.7.egg/nose/case.py", line 197, in runTest
self.test(self.arg)
File "/mnt/us/usr/local/lib/python2.7/dist-packages/fudge/patcher.py", line 79, in caller
value = fn(
args, *kw)
File "/mnt/us/soundcloud-python/soundcloud/tests/test_requests.py", line 33, in test_bad_responses
assert_raises(HTTPError, lambda: client.get('/me'))
File "/mnt/us/usr/lib/python2.7/unittest/case.py", line 476, in assertRaises
callableObj(
args, **kwargs)
File "/mnt/us/soundcloud-python/soundcloud/tests/test_requests.py", line 33, in
assert_raises(HTTPError, lambda: client.get('/me'))
File "/mnt/us/soundcloud-python/soundcloud/client.py", line 130, in _request
return wrapped_resource(make_request(method, url, kwargs))
File "/mnt/us/soundcloud-python/soundcloud/request.py", line 190, in make_request
result.raise_for_status()
File "/mnt/us/usr/local/lib/python2.7/dist-packages/requests/models.py", line 596, in raise_for_status
http_error_msg = '%s Client Error: %s' % (self.status_code, self.reason)
AttributeError: 'MockResponse' object has no attribute 'reason'


Ran 24 tests in 3.267s

FAILED (errors=1)

Woops. test Fayle! ;)

[root@kindle soundcloud-python] pip install -I requests==0.14.2
Downloading/unpacking requests==0.14.2
Downloading requests-0.14.2.tar.gz (361kB): 361kB downloaded
Successfully installed requests
Cleaning up...

[root@kindle soundcloud-python]
nosetests --with-doctest
Ran 24 tests in 2.203s

OK

@rabialam rabialam added a commit to rabialam/soundcloud-python that referenced this issue Dec 27, 2012
@rabialam rabialam (#17) use updated requests interface 20537ec
@rabialam rabialam added a commit to rabialam/soundcloud-python that referenced this issue Dec 27, 2012
@rabialam rabialam (#17) use updated requests interface 555add3
@rabialam rabialam added a commit to rabialam/soundcloud-python that referenced this issue Dec 27, 2012
@rabialam rabialam (#17) use updated requests interface 14ac88b
@rwblue

still got problem with Error attribute

@awjrichards

I've tested the above patch by @rabialam (14ac88b) and it appears to work. @rabialam have you submitted a pull request for this? It would be nice to have this working in the official SDK codebase :)

@Zintinio

It works for me as well.

@sebpiq

Error here as well. This will reproduce it :

import soundcloud
client = soundcloud.Client(client_id='YOUR_CLIENT_ID')
track = client.get('/tracks/52839')

A pull request for that patch, that would be nice :)

@Zintinio

The above patch causes one test to fail, and an error.

ERROR: Anything in the 400 or 500 range should raise an exception.
...
FAIL: Certain properties should be copied to the wrapped resource.
...

For now, (I'll submit a fix), perhaps it would be best to set requests==0.14.0 in requirements.txt
All tests pass with this.

@Zintinio Zintinio added a commit that referenced this issue Jan 31, 2013
@Zintinio Zintinio Fix #17 Updated requirements.txt to exclude requests>0.14.0
With requests > 0.14.0, soundcloud-python breaks, and running the tests
results in the error:

======================================================================
ERROR: Anything in the 400 or 500 range should raise an exception.
----------------------------------------------------------------------

With requests==0.14.0, all tests pass.
295ae13
@sebpiq

ok ... thanks for the tip!

@paulosman paulosman pushed a commit that closed this issue Feb 14, 2013
@Zintinio Zintinio Fixes #17 Updated to use requests 1.x
Requests 1.x no longer has an error attribute in Response objects,
and Response objects now expect a `reason` attribute in the
raise_for_status() method when building the error message. This was
causing errors in tests as well as any requests.

requirements.txt now specifies requests >= 1.0.0

tests/utils has had MockResponses updated to reflect the API change,
as well test_properties_copied() in tests/test_resource.

Tests have been run in requests 1.0.0 and 1.1.0
0639cc8
@paulosman paulosman closed this in 0639cc8 Feb 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment