i'm trying write python script that, command line, allow me to:
log in trello
use trello python api retrieve data trello boards, etc.
i'm restricted using python 2.7.6, please don't offer python 3 suggestions — won't able use them.
i'm able log in trello using requests module; however, i'm stuck on retrieving user key in order able use trello api.
here's i'm doing far:
import trello import requests # not shown: retrieve username , password user sess = requests.session() logindata = { 'method': 'password', 'factors[user]': username, 'factors[password]': password } trello_login_url = "https://trello.com/1/authentication" resp = sess.post(trello_login_url, trellologin) # resp => <response [200]>
at point, resp.text
consists of dictionary (which works equally in javascript or python) containing single key code
value long string of gibberish). assume (and 200 status code in response object) means logged in successfully.
so, i'm (presumably) logged in, request token url api:
api = trello.trelloapi(my_api_key) tokenurl = api.get_token_url('myapp') # => https://trello.com/1/authorize?key=<mykey>&name=myapp&expiration=30days&response_type=token&scope=read,write
but when try use url:
sess.get(tokenurl)
the response text (consisting of html authorization page) has "log in" button, rather "approve" button see when in browser. me, suggests requests.session
object not persisting properly. perhaps it's using incorrect cookies or in get()
request?
honestly, i'm not concerned nuts , bolts of what's going wrong, have fix it. how make session persist get()
call can next part?
(of course, it's entirely possible — — approach incorrect ground up, haven't been able find documentation tell me should doing differently, best come have found. if there instructions on doing way — still command line — feel free point me them.)
apparently there 2 calls make token:
- https://trello.com/1/authentication contains
code
string in response - https://trello.com/1/authorization/session use
code
retrieved post, should return 204 ,token
set cookies. (you need providedsc
string, detail please try inspect requests via chrome dev tools.)