Import os restricted and module not found errors

Hi! I am trying to run the code described in this article to retrieve earnings calls from the Python Codebook in LSEG Workspace:
. However when I try to import os and pysftp I get the following errors:RefiImportError: Import 'os' is restricted.
ModuleNotFoundError: No module named 'pysftp'
Could you please advise how to solve the following errors?
Thank you in advance!
Answers
-
Thank you for reaching out to us.
You can't use the os module on Codebook and the pysftp module is not available on Codebook.
Therefore, you can't run that sample code on Codebook.
You may need to setup your Jupyter Environment to run that example.
0 -
Thank you very much for your reply. I am now trying to run the example on my Jupyter Notebook. When I try to run this part of code:
if download_from_sftp: print("Connecting to SFTP server...") cnopts = pysftp.CnOpts() cnopts.hostkeys = None with pysftp.Connection(host=hostname, username=username, password=password, cnopts=cnopts) as sftp: print("Connection successfully established!") sftp.cwd(directory) files = sftp.listdir_attr() x_days_ago = datetime.now() - timedelta(days=lookback_days) recent_files = [(file.filename, datetime.fromtimestamp(file.st_mtime)) for file in files if datetime.fromtimestamp(file.st_mtime) > x_days_ago] df_recent_files = pd.DataFrame(recent_files, columns=['Filename', 'CreationDate']) for index, row in df_recent_files.head(max_files).iterrows(): remote_file = row['Filename'] local_file = os.path.join(local_directory, remote_file) sftp.get(remote_file, local_file) print(f"Downloaded the most recent files into the '{local_directory}' directory.")
I get the following error message:
Connecting to SFTP server...
C:\Miniforge3\Lib\site-packages\pysftp\__init__.py:61: UserWarning: Failed to load HostKeys from C:\Users\user\.ssh\known_hosts. You will need to explicitly load HostKeys (cnopts.hostkeys.load(filename)) or disableHostKey checking (cnopts.hostkeys = None). warnings.warn(wmsg, UserWarning)
--------------------------------------------------------------------------- gaierror Traceback (most recent call last) File C:\Miniforge3\Lib\site-packages\pysftp\__init__.py:176, in Connection._start_transport(self, host, port) 175 try: --> 176 self._transport = paramiko.Transport((host, port)) 177 # Set security ciphers if set File C:\Miniforge3\Lib\site-packages\paramiko\transport.py:484, in Transport.__init__(self, sock, default_window_size, default_max_packet_size, gss_kex, gss_deleg_creds, disabled_algorithms, server_sig_algs, strict_kex, packetizer_class)
483 reason = "No suitable address family"
--> 484 addrinfos = socket.getaddrinfo(
485 hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM
486 )
487 for family, socktype, proto, canonname, sockaddr in addrinfos:
File C:\Miniforge3\Lib\socket.py:978, in getaddrinfo(host, port, family, type, proto, flags)
977 addrlist = []
--> 978 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
979 af, socktype, proto, canonname, sa = res
gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
ConnectionException Traceback (most recent call last)
Cell In[5], line 11
8 cnopts.hostkeys = None
10 # Establish the connection
---> 11 with pysftp.Connection(host=hostname, username=username, password=password, cnopts=cnopts) as sftp:
12 print("Connection successfully established!")
14 # Change to the target directory
File C:\Miniforge3\Lib\site-packages\pysftp\__init__.py:140, in Connection.__init__(self, host, username, private_key, password, port, private_key_pass, ciphers, log, cnopts, default_path)
138 # Begin the SSH transport.
139 self._transport = None
--> 140 self._start_transport(host, port)
141 self._transport.use_compression(self._cnopts.compression)
142 self._set_authentication(password, private_key, private_key_pass)
File C:\Miniforge3\Lib\site-packages\pysftp\__init__.py:183, in Connection._start_transport(self, host, port)
180 self._transport.get_security_options().ciphers = ciphers
181 except (AttributeError, socket.gaierror):
182 # couldn't connect
--> 183 raise ConnectionException(host, port)
ConnectionException: ('ftp-setranscripts.lseg.com', 22)Could you please suggest a way to solve the issue or if I should write a different hostname than the one in the example? The hostname in the example is "ftp-setranscripts.lseg.com".
Thank you very much!0 -
It looks like to be a connection issue.
The library can't establish a connection to the ftp-setranscripts.lseg.com server.
You can use other ssh tools or contact your IT support team to verify the connection.
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 37 Alpha
- 167 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 707 Datastream
- 1.5K DSS
- 633 Eikon COM
- 5.2K Eikon Data APIs
- 14 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 6 Trading API
- 3K Elektron
- 1.5K EMA
- 259 ETA
- 570 WebSocket API
- 40 FX Venues
- 16 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 25 Messenger Bot
- 4 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 284 Open PermID
- 47 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 24 RDMS
- 2.2K Refinitiv Data Platform
- 890 Refinitiv Data Platform Libraries
- 5 LSEG Due Diligence
- 1 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
- 124 Open DACS
- 1.1K RFA
- 108 UPA
- 196 TREP Infrastructure
- 232 TRKD
- 920 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 105 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛