question

Upvotes
Accepted
3 0 0 0

Attempt to request Authentication Token fails with 401

This function is taken from the examples slightly modified:

def getAuthenticationToken(self, userName, password):
        authReqUrl = self.baseUrl + "Authentication/RequestToken"
        credentialsData = {'Credentials': {'Username': userName, 'Password': password}}

        r = requests.post(url=authReqUrl, json=credentialsData, headers=self.requestHeaders)

        if (r.status_code == 200):
            jsonResponse = json.loads(r.text.encode('ascii', 'ignore'))
            token = {'timestamp': datetime.datetime.now(), 'token': jsonResponse["value"]}
            with open('TRTH_token.pkl', 'wb') as handle:
                pickle.dump(token, handle, protocol=pickle.HIGHEST_PROTOCOL)
            return token
        else:
            print("ERROR: could not retrieve authentication token, check username and password:")
            print("Status code: ", r.status_code, "\nResponse:\n", r.text)
            sys.exit()

This returns the following response:

Status code:  401 
Response:
 {"error":{"message":"Invalid username or password"}}

The username and passwords sent as args are the ones corresponding to this website. I tried using both email and username, but neither work. Eventually, this is what I'm looking for; a simple mapping which requires authentication, therefore this question.

Thanks!

pythontick-history-rest-apisymbologytoken
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

My fault for not being thorough enough. Both this article and this metadata clearly indicate to contact a Thomson Reuters account manager for this issue. @Konstantin Pavlov had the same problem, as he describes in the comments of the article. Furthermore, the ThomsonReuters.Dss.Api.Authentication namespace specifies:

<Annotation Term="Org.OData.Core.V1.LongDescription" String="Talk to your DataScope representative about getting DataScope credentials. The API accepts the same credentials used for FTP and Web GUI."/>

Perhaps I could rephrase my question this way, who can I contact for DSS username and password? and how can I contact the representative? Any guidance on this is highly appreciated. Cheers!

Upvotes
Accepted
23k 22 9 14

Hello @hello_world,

Please note that credentials used for this community are set at self-registration and anyone can register and be a member of this community, and obtain these creds.

TRTH and DSS credentials are assigned to customers, as part of their subscription to the product. Please contact you Refinitiv Account manager, if your organization has the product and you need help with credentials.

If you are looking to purchase or sign up for a trial, directly contact local Refinitiv sales team at https://www.refinitiv.com/en/contact-us for more information

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
18k 21 12 20

Hi @hello_world

I modified your code a little bit to make it executable.

And I can successfully get the token.

Code:

import requests
import json
import datetime

def getAuthenticationToken(userName, password):
        authReqUrl = "https://hosted.datascopeapi.reuters.com/RestApi/v1/Authentication/RequestToken"
        credentialsData = {'Credentials': {'Username': userName, 'Password': password}}

        headers = {
                    'Prefer': 'respond-async',
                    'Content-Type': 'application/json'
                }
        
        r = requests.post(url=authReqUrl, json=credentialsData, headers=headers)

        if (r.status_code == 200):
            jsonResponse = json.loads(r.text.encode('ascii', 'ignore'))
            token = {'timestamp': datetime.datetime.now(), 'token': jsonResponse["value"]}
            #with open('TRTH_token.pkl', 'wb') as handle:
            #    pickle.dump(token, handle, protocol=pickle.HIGHEST_PROTOCOL)
            return token
        else:
            print("ERROR: could not retrieve authentication token, check username and password:")
            print("Status code: ", r.status_code, "\nResponse:\n", r.text)
            sys.exit()


user = 'xxxxyyyy'
password = 'xxxxyyyy'
getAuthenticationToken(userName=user, password=password)



ahs.jpg (248.6 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Thanks for your reply @chavalit.jintamalit but it still doesn't work. I believe the credentials are simply incorrect because the username (email/user) and password with which I login into this community are the same sent as json, and the response (401) is always the same. This question talks about something similar, and the answer indicates towards a DSS username and password. Where can I get these? I mean, there is lack of documentation regarding to what username and password are required for any API. To my knowledge up to this extent there are developer community credentials, DDS credentials, Platform credentials, and whatsoever.

Click below to post an Idea Post Idea