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 ?
Best Answer
-
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)0
Answers
-
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
0 -
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
0 -
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.
0 -
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)
0 -
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)?
0 -
Thank you for the tip. Indeed, it works now when I run python3 myscript.py !
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 687 Datastream
- 1.4K DSS
- 622 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 254 ETA
- 557 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 276 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 678 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 91 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛