Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Refinitiv Data Platform /
  • Refinitiv Data Platform Libraries /
avatar image
Question by simon.corde-e · Feb 11, 2020 at 05:33 PM · websocketrdp library.

Connection to streaming news works in jupyter notebook but not in python script

Hello,


I am currently trying to retrieve streaming news for RDP platform.


When I run the following code in a jupyter notebook cell all is working fine :


import refinitiv.dataplatform as rdp

import datetime

import zlib

import base64

import json

APP_KEY = '***'

MACHINE_ID = '***'

PASSWD = '***'


rdp.open_platform_session(app_key=APP_KEY, 
                          grant=rdp.GrantPassword(username=MACHINE_ID, 
                                                  password=PASSWD)
                          )
 
item_stream = rdp.ItemStream(session=rdp.get_default_session(),
                             domain=DOMAIN,
                             name=NAME, #should be optional
on_refresh = lambda item_stream, event : processMRNstart("Refresh", event),
on_update = lambda item_stream, event : processMRNUpdate("Update", event),
on_status = lambda item_stream, event : processMRNstart("Status", event),
on_complete = lambda item_stream : processMRNstart("Complete", "")
                            )
item_stream.open()


However, when I copy paste this code into a python script .py and run in into the command shell it stucks around the rpd.open_platform_session function and nothing happens.


Any ideas about the different behavior between Jupyter notebook and Python scripts for getteting streaming news from RDP platform ?



Natalia.Skaczkowska

People who like this

1 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.

5 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by zoya.farberov · Feb 12, 2020 at 06:01 PM

Hi @simon.corde-e,

I suspect what is happening. Try the following, let us know how this works for you:

import refinitiv.dataplatform as rdp
import datetime
import zlib
import base64
import json
import time

app_key = 'YOURKEY'
user = 'YOURUSER'
password = 'YOURPASSWORD'

rdp.open_platform_session(app_key=app_key,
     grant=rdp.GrantPassword(username=user,
     password=password)
     )
item_stream = rdp.ItemStream(session = rdp.get_default_session(),
     name = "EUR=",
     on_refresh = lambda s, msg : print(json.dumps(msg, indent=2)),
     on_update = lambda s, msg : print(json.dumps(msg, indent=2)),
     on_status = lambda s, msg : print(json.dumps(msg, indent=2)))

item_stream.open()
while True: time.sleep(0.2) 
Comment
simon.corde-e

People who like this

1 Show 1 · 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
simon.corde-e · Feb 13, 2020 at 10:18 AM 0
Share

Thank you for the tip. Indeed, it works now when I run python3 myscript.py !

avatar image
REFINITIV
Answer by zoya.farberov · Feb 11, 2020 at 07:19 PM

Hello @simon.corde-e,

For me this code runs the same from jupyter notebook and from python script in command shell.

Are you finding the same version of python, with the same versions of the libraries installed, via jupiter python as you do via command shell?

To confirm, run from pybook and from shell:

python --version
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.

avatar image
REFINITIV
Answer by wasin.waeosri · Feb 12, 2020 at 04:15 AM

Hello @simon.corde-e

I have tried the code with both Python Console and Jupyter Notebook. They can run and give the same result.

Did you run Notebook and Console on the same Python environment as suggest by my colleague above?

Beside the Python version, you also need to same libraries (and versions) as well. You can use the following commands to list the installed libraries

  • Conda/Mini Conda: conda list
  • Python Pip: pip list
Comment
SupDev1

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 simon.corde-e · Feb 12, 2020 at 09:45 AM

Thank you for your quick answer.

In fact, I use exactly the same environment between shell and jupyter notebook (same python version and same libraries versions).

I switch from a windows environement in which I launched my python script from the powershell to a linux environment and the connexion now works (the status is displayed as open). However, in the python script I print and write the incoming streaming news. In jupyter notebook it is ok but from the shell (I run the following command python3 myscript.py) there is no print in the shell console nor anything written in the output file.


I have instanciated a logger to see what is happenning and it appears we get the status event ('status': <StreamState.Open: 3>) then the refresh event but the logs stop afterwards.

Comment

People who like this

0 Show 1 · 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
simon.corde-e · Feb 12, 2020 at 01:38 PM 0
Share

The command python3 -i myscript.py allows to run the script and open a python command prompt. Is it an expected behavior that getting the streaming news from a Jupyter Notebook or a python command prompt works but not when run from the console as python3 myscript.py ? Indeed, we intend to run the extraction of the news in the background (we would like to run it 24/24H on a linux server)

avatar image
REFINITIV
Answer by wasin.waeosri · Feb 13, 2020 at 04:08 AM

Hello @simon.corde-e

Could you please also give us the full source code of your Python script (especially the processMRNstart and processMRNupdate functions source code)?


Comment
SupDev1

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.

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 >
8 People are following this question.

Related Questions

How to get dividend with rdp

RDP Python API performance

RDP libraries: 'Request' object has no attribute 'prepare'

RDP 1.0.0a6 Proxy error

Cannot retreive chains with RDP Chains class

  • 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