Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Eikon Data APIs /
avatar image
Question by noel.randewich · Nov 16, 2020 at 04:52 PM · pythoneikon api

KeyError: 'headlines'

Hi,

I'm trying to iterate through several RICs and dates collecting news stories using this, and variations of this.

In the code below, x is a list of anywhere from 3 to 500 RICs.

for y in dates[1::60]:
        sdate = y
        edate = y
        edate += timedelta(days=60)
        str_sdate = sdate.strftime("%d-%b-%Y %H:%M:%S.%f")
        str_edate = edate.strftime("%d-%b-%Y %H:%M:%S.%f")
        q="R:" + x + ' Language:LEN AND NS:RTRS US AND -BRIEF -FACTBOX -IMBALANCE -AA -MOODY -MEDIA-'
        stories = ek.get_news_headlines(q, date_from = str_sdate,  date_to = str_edate, count = 100)

When I run it, it works for anywhere between 1 minute and 20 minutes, giving me a few dozen or a few hundred results, but it always eventually fails with this error code:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-4-772ef7887bd0> in <module>
     14         str_edate = edate.strftime("%d-%b-%Y %H:%M:%S.%f")
     15         q="R:" + x + ' Language:LEN AND NS:RTRS US AND -BRIEF -FACTBOX -IMBALANCE -AA -MOODY -MEDIA-'
---> 16         stories = ek.get_news_headlines(q, date_from = str_sdate,  date_to = str_edate, count = 100)
     17         storycount = stories['versionCreated'].count()
     18 
~\Anaconda3\lib\site-packages\eikon\news_request.py in get_news_headlines(query, count, date_from, date_to, raw_output, debug)
    124         return result
    125     else:
--> 126         return get_data_frame(result)
    127     128 
~\Anaconda3\lib\site-packages\eikon\news_request.py in get_data_frame(json_data)
    133                              'sourceName', 'versionCreated']
    134 --> 135     json_headlines_array = json_data['headlines']
    136     first_created = [tz_replacer(headline['firstCreated']) for headline in json_headlines_array]
    137     headlines = [[headline[field] for field in Headline_Selected_Fields] 
KeyError: 'headlines'

I have tried shortening my query to make it simpler, taking out everything but language, RIC and news source. I have tried inserting a 3 second delay between each iteration in case there is some limit on how often I can make a request, but no matter what I change, I always eventually get the "KeyError: 'headlines'" error.

I see other questions have been asked about "KeyError: Header" but I can't see anything related to "KeyError: Headline".

Thank you

People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

2 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by Alex Putkov. · Nov 16, 2020 at 10:24 PM

Every time get_news_headlines method is executed Eikon Data APIs library uses the values provided in the arguments to construct an HTTP request, which is sent to the Web service providing news headlines. The expected response contains JSON, which includes 'headlines' key. You can see it by including raw_output=True kwarg in get_news_headlines method. When 'headlines' keyword is missing in the response, this indicates a failed request. Printing out full response, which you can obtain by including raw_output=True kwarg in get_news_headlines method, may provide a clue why the request failed. Capturing failed request with Fiddler would be even better. This said, an HTTP request may fail for any number of reasons. If what you experience is one request failing out of hundreds, it may not be worth investigating. You could just add defensive code to your script to resubmit the request when it fails. But if you have a high number of requests failing, then it's definitely worth looking into. A Fiddler capture of a failed request would be most helpful. Here's an example of defensive code that resubmits the request when KeyError is encountered.

for y in dates[1::60]:
        sdate = y
        ...
        try:
            stories = ek.get_news_headlines(q, date_from = str_sdate, 
                                            date_to = str_edate, count = 100)
        except KeyError:
            stories = ek.get_news_headlines(q, date_from = str_sdate, 
                                            date_to = str_edate, count = 100)
Comment
noel.randewich

People who like this

1 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
Answer by noel.randewich · Nov 17, 2020 at 12:54 AM

HI @Alex Putkov. I will experiment with the exception code you showed me above.

I really appreciate your patience with all my questions recently.

Tks

Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
11 People are following this question.

Related Questions

In eikon Python api function eikon.get_news_headlines() are results inclusive of date_from and date_to timestamps parameters?

RICs yield lesser data than on Eikon

Replicate GOVSRCH function in Python

Avoid Eikon from giving the last available value for a date outside of a request.

Python Eikon API to Reuters Stock Screen

  • Feedback
  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Careers
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Calais
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRIT
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • World-Check Data File
  • Explore
  • Tags
  • Questions
  • Badges