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

ResourceUnavailable after calling some APIs containing write operations #42

Closed
kennethzfeng opened this issue May 4, 2014 · 3 comments · Fixed by #43
Closed

ResourceUnavailable after calling some APIs containing write operations #42

kennethzfeng opened this issue May 4, 2014 · 3 comments · Fixed by #43

Comments

@kennethzfeng
Copy link
Contributor

Hi,

I am using py-trello for a project. One of the dependency 'oauth2' was missing from the PyPI version of the package, which is very old (0.6.0). I was able to figure the oauth2.Consumer class was present in later release of the package by using the latest simplegeo/python-oauth2. However, the program seems to behave very weird. I kept getting HTTP 400 randomly. I was able to have some lucks with py-trello until making a call to anything contains write operation like below.

The token requested contains read and write access. Expiration was set to never.

I tested the same operations using requests. It worked fine without issues.

client = TrelloClient(api_key=TRELLO_API_KEY, api_secret=TRELLO_API_SECRET,
                              token=token, token_secret=token_secret)

boards = client.list_boards()
b = boards[0]
print b
lists = b.all_lists()
try:
    for l in lists:
        l.add_card("Hello")
except:
    print "Something wrong"
print b.open_lists()

Here is the stack trace

Traceback (most recent call last):
  File "test_py_trello.py", line 20, in <module>
    print b.open_lists()
  File "/Users/kennethfeng/anaconda/lib/python2.7/site-packages/trello/__init__.py", line 283, in open_lists
    return self.get_lists('open')
  File "/Users/kennethfeng/anaconda/lib/python2.7/site-packages/trello/__init__.py", line 293, in get_lists
    query_params = {'cards': 'none', 'filter': list_filter})
  File "/Users/kennethfeng/anaconda/lib/python2.7/site-packages/trello/__init__.py", line 177, in fetch_json
    raise ResourceUnavailable(url, response)

trello.ResourceUnavailable: Resource unavailable: https://api.trello.com/1/boards/*******************/lists?key=****************************&token=********************************&cards=none&filter=open (HTTP status: 400)

I forked the library and ran nosetests -v test/. It seems to confirm my observation.

test01_list_boards (test_trello.TrelloClientTestCase) ... ok
test10_board_attrs (test_trello.TrelloClientTestCase) ... ok
test20_board_all_lists (test_trello.TrelloClientTestCase) ... ok
test21_board_open_lists (test_trello.TrelloClientTestCase) ... ok
test22_board_closed_lists (test_trello.TrelloClientTestCase) ... ok
test30_list_attrs (test_trello.TrelloClientTestCase) ... ok
test40_list_cards (test_trello.TrelloClientTestCase) ... ok
test50_add_card (test_trello.TrelloClientTestCase) ... FAIL
test51_add_card (test_trello.TrelloClientTestCase) ... FAIL

======================================================================
FAIL: test50_add_card (test_trello.TrelloClientTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kennethfeng/dev/repos/py-trello/test/test_trello.py", line 90, in test50_add_card
    self.fail("Caught Exception adding card")
AssertionError: Caught Exception adding card
-------------------- >> begin captured stdout << ---------------------
can't set attribute

--------------------- >> end captured stdout << ----------------------

======================================================================
FAIL: test51_add_card (test_trello.TrelloClientTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kennethfeng/dev/repos/py-trello/test/test_trello.py", line 116, in test51_add_card
    self.fail("Caught Exception adding card")
AssertionError: Caught Exception adding card
-------------------- >> begin captured stdout << ---------------------
can't set attribute

--------------------- >> end captured stdout << ----------------------

----------------------------------------------------------------------
Ran 9 tests in 2.976s

FAILED (failures=2)

If you could quickly pin point the issue, that's great.

If not, that's still fine. It seems like it's better to migrate to requests from httplib2 and to rauth from oauth2. If you agree, I will send you pull requests after I am done with the migration.

Kenneth

@hany55
Copy link

hany55 commented May 8, 2014

@kennethzfeng I just installed your fixes and I'm still getting 400 - Resource unavailable on write operations. Just curious if you still face the issue with this fix?

@kennethzfeng
Copy link
Contributor Author

@hany55 Let me take a look tonight.

@kennethzfeng
Copy link
Contributor Author

Hi @hany55, You are right. I am still getting the errors with the same script I ran. It seems to be very specific to the oauth2 implementation. The same url coming out of the error message generates a successful response using requests and other web browsers.

iksteen added a commit to voipro/py-trello that referenced this issue May 26, 2014
oauth2 is pretty strict about the uppercase T and basically ruins
the request: It doesn't put the OAuth data in the request's headers
but replaces the body instead. Refs sarumont#42.
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 a pull request may close this issue.

2 participants