question

Upvotes
Accepted

Cannot retrieve ESG data via RDP libraries in Python

I am using RDP libraries to retrieve ESG data via the delivery layer as per the tutorial written here:

https://developers.refinitiv.com/article/discover-our-upcoming-refinitiv-data-platform-library-part-2-0


However, when I try it with my code, it says:

EndpointError: Error code -1 | Session is not opened. Can't send any request


Not really sure why. Here is my code below (I removed my real RDP login and pwd for security purpose):

import refinitiv.dataplatform as rdp

APP_KEY = 'DEFAULT_CODE_BOOK_APP_KEY'
RDP_LOGIN = '<MY LOGIN HERE>'
RDP_PASSWORD = '<MY PWD HERE>'

session = rdp.PlatformSession(
    APP_KEY,
    rdp.GrantPassword(username=RDP_LOGIN, password=RDP_PASSWORD)
)

endpoint_url = 'data/environmental-social-governance/v1/views/scores-full'
endpoint = rdp.Endpoint(session, endpoint_url)
response = endpoint.send_request(method=rdp.Endpoint.RequestMethod.GET, query_parameters={'universe': 'ADVANC.BK'})

My environment is in Codebook.

pythonrdp-apirefinitiv-data-platformrefinitiv-data-platform-libraries
icon clock
10 |1500

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

Upvotes
Accepted
24.9k 86 10 22

Hi @Ativut.Trikalsaransukh

Are you doing the above in CodeBook or your own offline Jupyter or .py file?

Just checking because you have the Codebook APP Key - but then you are trying to open a PlatformSession?

Since codebook is part of Eikon, you should be using a desktop session (i.e. an Eikon/Workspace Session) as explained.

session = rdp.open_desktop_session('DEFAULT_CODE_BOOK_APP_KEY')

However, once you do that and make the request it would appear that the Codebook is not permissioned yet to consume ESG data.

If I print the raw response data:

print(response.data.raw)

I get the following:

{'error': {'id': '2d2199a1-6fca-4ac4-a6e6-dd3fcc6655aa', 'code': 'insufficient_scope', 'message': 'access denied. Scopes required to access the resource [trapi.data.esg.views-scores-full.read]', 'status': 'Forbidden'}}

So, for now - if you want to consume ESG data, I suspect you will need to install Python locally and execute the code locally with a PlatformSession - assuming you MachineID is licensed for ESG data.

If however, you are running locally, then it could be that your session fails because you don't have a valid AppKey?

Once you confirm where/how you are running your script, I will reach out to the Codebook owner to comment if appropriate.

icon clock
10 |1500

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

Upvotes
9.6k 10 6 7

Hello @Ativut.Trikalsaransukh

I can replicate the problem using the given source code.

When I change from rdp.PlatformSession(..) to be rdp.open_platform_session(..) then I can get ESG data:

My source code:

session = rdp.open_platform_session(
    APP_KEY,
    rdp.GrantPassword(username=RDP_USER, password=RDP_PASSWORD)
)
endpoint_url = 'data/environmental-social-governance/v1/views/scores-full'
endpoint = rdp.Endpoint(session, endpoint_url)
response = endpoint.send_request(method=rdp.Endpoint.RequestMethod.GET, query_parameters={'universe': 'ADVANC.BK'})
result = response.data.raw
result

result:

Note: I run the source code above in Jupyter notebook.


result.png (20.7 KiB)
icon clock
10 |1500

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

Upvotes

Hello @Umer Nalla and @Pimchaya.Wongrukun

Thank you both for your insights. To clarify Umer's doubt, I am doing this in Codebook.


I guess I am just confused with the difference between DesktopSession / PlatformSession and open_desktop_session / open_platform_session. In the document, it says that the first should be used in Content Layer and the latter should be used in Function Layer. So is it safe to assume that for data that is currently only available in Delivery Layer, the "open" one should be used?


Next is the Codebook environment, based on Umer's info, is it safe to summarize that:

1) Codebook is not ready to retrieve ESG data yet.

2) Once it's ready, open_desktop_session should be used so I should not have to supply my RDP credential


And lastly on local Jupyter environment:

I tried just a moment ago and it does work indeed. I have to replace my APP_KEY to my own and as Pimchaya mentioned, I will need to use open_platform_session function

icon clock
10 |1500

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

Upvotes
24.9k 86 10 22

Hi @Ativut.Trikalsaransukh

Your welcome.

For clarification of Session type, please refer to part 1 of my article - where I explain the difference between the session types - Dekstop(Eikon/WorkSpace), Platform(Cloud) and Deployed(ADS).

Just to complicate matters slightly, in the future versions of RDP library both Cloud and ADS will be classed as Platform Session (the format of the call will be different).

The session type is independent of the Library layer i.e. Function, Content or Delivery - which reflect different levels of ease of use etc.

At present, you need to use the Delivery layer for ESG data - but in the new version of the RDP library(not generally available yet), there is Function layer support for ESG - thereby making it easier - no need to create Endpoints etc:

df = rdp.get_esg_standard_scores(universe = '6758.T') 

But as mentioned this is not available just yet.

Finally, would you be OK if we remove the Internal status of this post, as I think the content will be helpful to customers once they start trialling CodeBook?

Thanks.

icon clock
10 |1500

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

Thank you. Sure I will remove the internal flag on this.