So I have a method where I log into a third party API which responds with a cookie as you can see in my code.
Now I wanted to pass these cookies to the ShowUCPList method so I can call the next URL which needs these cookies to retrive the anime list of my user, but it just wont work, it seems like the cookies are in the container but if I call my next URL it just ignores them.
@route(PREFIX + '/ucp')
def ShowUCP(title):
oc = ObjectContainer(title2 = title)
url = WebsiteAPIURL + '/user/login'
values = { 'api_key' : WebsiteAPIKey, 'username' : Prefs['username'], 'password' : Prefs['password'] }
result = JSON.ObjectFromURL(url, values)
cookies = HTTP.CookiesForURL(url)
# some other code
oc.add(DirectoryObject(key=Callback(ShowUCPList, title=L('title.animelist'), url=WebsiteAPIURL + '/ucp/list', cookies=cookies), title=L('title.animelist')))
return oc
@route(PREFIX + '/ucp/list', page=int)
def ShowUCPList(title, url, cookies, page = 0):
oc = ObjectContainer(title2 = title, http_cookies=cookies)
values = { 'api_key' : WebsiteAPIKey, 'kat' : 'anime', 'limit' : '50', 'p' : page }
result = JSON.ObjectFromURL(url, values)
...
The code above doesn't work. The cookies variable is filled and if I Log(oc.http_cookies) then it shows the cookies in the log, so the cookies don't get lost, but they won't get used from my next request and I can't figure out why..
@route(PREFIX + '/ucp/list', page=int)
def ShowUCPList(title, url, page = 0):
oc = ObjectContainer(title2 = title)
login_url = WebsiteAPIURL + '/user/login'
values = { 'api_key' : WebsiteAPIKey, 'username' : Prefs['username'], 'password' : Prefs['password'] }
result = JSON.ObjectFromURL(login_url, values)
values = { 'api_key' : WebsiteAPIKey, 'kat' : 'anime', 'limit' : '50', 'p' : page }
result = JSON.ObjectFromURL(url, values)
The code above works fine, but I have several other methods where I need the cookies and sending two requests per method is not what I want...