question

Upvotes
Accepted
18 0 1 4

News retrieval using rdp.get_news_story

Hi Team,

I am trying to pull in news stories using rdp.get_news_story, but no format seems to be working

I am using a dedicated RDP account and I can pull in headlines just fine ex. using

rdp.get_news_headlines(query="R:VOD.L AND LEN", date_from="2021-03-06T09:00:00", \
                       date_to="2021-03-08T18:00:00", count=10, sort_order='newToOld')

but the subsequent story retrieval isn't working ex. for story ID urn:newsml:reuters.com:20210308:nBw12DM8da:1

I would assume it would behave the same way as eikon DAPI where I just need to supply the ID/PNAC string but the below don't work

rdp.get_news_story(story_id='urn:newsml:reuters.com:20210308:nBw12DM8da:1')
rdp.get_news_story(story_id='nBw12DM8da')

I also tried parsing the url into the same format indicated in the context menu for the function, but still no luck

import urllib
test = urllib.parse.quote('urn:newsml:reuters.com:20210308:nBw12DM8da:1', \
                          encoding='utf-8', errors='replace')
rdp.get_news_story(story_id=test)

Any hints how to access the story using that ID?

rdp-apirefinitiv-data-platformnewsrefinitiv-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.

Private questions are only used when client identifying information is included. Making this question public.

@leszek.lubecki

Hi,

Thank you for your participation in the forum.

Are any of the replies below satisfactory in resolving your query?

If yes please click the 'Accept' text next to the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,


AHS


Upvotes
Accepted
22.1k 59 14 21

Hi @leszek.lubecki,

I think this is a shortcoming in the RDP Python library. The library is sending in an accept header with */*, where as the documentation clearly mentions that only text/html or application/json is accepted. The server response is different based on what the application sends in accept header.

RDP library:

GET https://api.refinitiv.com/data/news/v1/stories/urn%3Anewsml%3Areuters.com%3A20210308%3AnBw12DM8da%3A1 HTTP/1.1
host: api.refinitiv.com
user-agent: python-httpx/0.14.3
accept: */*
accept-encoding: gzip, deflate
connection: keep-alive
authorization: Bearer ***
x-tr-applicationid: D6D7***DDD74

Here is the description in the RDP documentation:

I will raise this issue with the product team. Meanwhile, if you like, you can use requests module to make your own API call to news story:

import requests

headers = {
    'Accept': 'application/json',
    'Authorization': 'Bearer **YOUR ACCESS TOKEN**'
}

response = requests.request("GET", "https://api.refinitiv.com/data/news/v1/stories/urn:newsml:reuters.com:20210308:nBw12DM8da:1", headers=headers, data={})

print(response.text)



1620330825635.png (25.0 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.

Upvote
17.3k 82 39 63

Hi @leszek.lubecki,

The proper way to retrieve a story is how you performed above with the following line:

rdp.get_news_story(story_id='urn:newsml:reuters.com:20210308:nBw12DM8da:1')

Can you retrieve the status from this call? Do this:

rdp.get_last_status()
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.

Hey @nick.zincone.1

I get this:

{'http_status_code': 400, 'http_reason': 'Bad Request', 'error': {'id': 'acac01d2-4b36-4299-bb83-364a859e59be',  'code': '400',  'message': 'Validation error',  'status': 'Bad Request',  'errors': [{'key': 'accept',    'reason': 'validation failure list:\naccept in header should be one of [application/json text/html]'}]}}


Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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