0

Im trying to make a request to the API:https://www.trakomatic.com/

Code used:

import requests
url = 'https://webapi.trakomatic.com/....'

head1 = {'Authorization': 'access_token 066bf0a8d74xxxx'}
head2 = {'Authorization': '066bf0a8d74xxxx'}
head3 = {'Authorization': 'Token : 066bf0a8d74xxxx'}
head4 = {"Token":"066bf0a8d74xxxx"}


response = requests.post(url, headers= head3)

The API requires a token to make an HTTP request.Currently I am using the token provided by the API, perhaps is expiring. I am getting the following error.

>>>response.text
u'{"Status":"ERROR","Message":"Invalid or NULL token","Data":null}' 
>>>response
<Response [200]>

I have tried various formats of the header,as I suspected it maybe the cause but to no avail. Is there a way where I can use the username and password to generate the token? Is there something wrong with what I am doing?

The authentication page of the API has this:

URL Format[web api server]/account/authenticate/ 
URLhttps://webapi.trakomatic.com/account/authenticate/
Parameter(s){ LoginName: , Password: }

Tried using requests:

from requests.auth import HTTPBasicAuth
u = 'xxx' 
p = 'xxx'
>>> 

a=requests.post('https://webapi.trakomatic.com/account/authenticate/', auth=HTTPBasicAuth('u', 'p'))
>>> a
<Response [200]>
>>> a.json()
{u'Status': u'ERROR', u'LoginName': None, u'CorporationId': 0, u'Token': None, u'Msg': u'Invalid information to login', u'Password': None}
5
  • Use a requests session - logging in using the session should provide cookies which will be stored in the session and autoamtically provided by requests with each subsequent request using the session. i.e. you shouldn't have to manually provide a token unless it is an actual API key that the service documents the need to provide in the headers Commented Dec 8, 2015 at 11:12
  • Another way of at least understanding what is going on is to snoop a browser login using e.g. Fiddler Commented Dec 8, 2015 at 11:14
  • Updated question, is that what you are referring to. Commented Dec 8, 2015 at 11:22
  • If you can't login then there's no point trying to make any other requests. Perhaps the website needs a specific header - some will try to ensure that the request is from a browser because they don't want programs to login - like I say, try snooping a browser login, then replicate the headers. Of course, this may just be a sign that the website doesn't allow programmatic login, need to check their terms of service which are probably applicable to all (even programmatic) logins. Commented Dec 8, 2015 at 11:28
  • goggle for Fiddler Telerik Commented Dec 8, 2015 at 11:40

1 Answer 1

1

Solved the issue using Beautiful Soup:

from BeautifulSoup import BeautifulSoup
import urllib

post_params = {"token":"xxxx"}
post_args = urllib.urlencode(post_params)

url = 'https://webapi.trakomatic.com/....'
tag = urllib.urlopen(url, post_args)
rest = BeautifulSoup(tag)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.