Currently, I am encountering an error when using either rd, or ld while making data requests through the API gateway. The error is: "LDError: 'dict' object has no attribute 'url'". Please assist me with this issue.
rd
ld
"LDError: 'dict' object has no attribute 'url'"
@thanhct2005
Thank you for reaching out to us.
You may need to able the debug log in the library to verify what the problem is by using the following code.
config = ld.get_config() config.set_param("logs.transports.file.enabled", True) config.set_param("logs.transports.file.name", "lseg-data-lib.log") config.set_param("logs.level", "debug") ld.open_session(….)
The lseg-data-lib.log file will be created. We may be able to see the cause of the problem in the log file.
Yes, it seems the error continues.
I attached the log file.
Can you expand the Traceback… to see the code that causes this error?
AttributeError Traceback (most recent call last) Cell In[1], line 6 4 config.set_param("logs.transports.file.name", "lseg-data-lib.log") 5 config.set_param("logs.level", "debug") ----> 6 ld.open_session()
File D:\news.venv\Lib\site-packages\lseg\data_access_layer\session.py:91, in open_session(name, app_key, config_name) 88 set_default(new_session) 89 default_session = new_session ---> 91 default_session.open() 93 return default_session
File D:\news.venv\Lib\site-packages\lseg\data_core\session_session.py:374, in Session.open(self) 372 self._call_on_state("Session opening in progress") 373 self._config.on(configure.ConfigEvent.UPDATE, self._on_config_updated) --> 374 self._http_service.open() 375 is_opened = self._connection.open() 377 if is_opened:
File D:\news.venv\Lib\site-packages\lseg\data_core\session\http_service.py:334, in HTTPService.open(self) 333 def open(self): --> 334 self._client.open()
File D:\news.venv\Lib\site-packages\lseg\data_core\session\http_service.py:187, in HTTPClient.open(self) 183 proxies = self._session._proxies.get_proxy_for_httpx() 185 # httpx has its default Accept header and 186 # server wants application/json or nothing --> 187 self._client = get_httpx_client( 188 headers={"Accept": APPLICATION_JSON}, 189 limits=limits, 190 proxies=proxies, 191 ) 193 key = configure.keys.http_auto_retry_config 194 auto_retry_config = config.get(key, None)
File D:\news.venv\Lib\site-packages\lseg\data_core\session\http_service.py:160, in get_httpx_client(proxies, **kwargs) 158 def get_httpx_client(proxies, **kwargs): 159 if httpx.version >= "0.26.0": --> 160 client = httpx.Client(proxy=proxies, **kwargs) 161 else: 162 client = httpx.Client(proxies=proxies, **kwargs)
File D:\news.venv\Lib\site-packages\httpx_client.py:697, in Client.init(self, auth, params, headers, cookies, verify, cert, trust_env, http1, http2, proxy, mounts, timeout, follow_redirects, limits, max_redirects, event_hooks, base_url, transport, default_encoding) 686 proxy_map = self._get_proxy_map(proxy, allow_env_proxies) 688 self._transport = self._init_transport( 689 verify=verify, 690 cert=cert, (...) 695 transport=transport, 696 ) --> 697 self._mounts: dict[URLPattern, BaseTransport | None] = { 698 URLPattern(key): None 699 if proxy is None 700 else self._init_proxy_transport( 701 proxy, 702 verify=verify, 703 cert=cert, 704 trust_env=trust_env, 705 http1=http1, 706 http2=http2, 707 limits=limits, 708 ) 709 for key, proxy in proxy_map.items() 710 } 711 if mounts is not None: 712 self._mounts.update( 713 {URLPattern(key): transport for key, transport in mounts.items()} 714 )
File D:\news.venv\Lib\site-packages\httpx_client.py:700, in <dictcomp>(.0) 686 proxy_map = self._get_proxy_map(proxy, allow_env_proxies) 688 self._transport = self._init_transport( 689 verify=verify, 690 cert=cert, (...) 695 transport=transport, 696 ) 697 self._mounts: dict[URLPattern, BaseTransport | None] = { 698 URLPattern(key): None 699 if proxy is None --> 700 else self._init_proxy_transport( 701 proxy, 702 verify=verify, 703 cert=cert, 704 trust_env=trust_env, 705 http1=http1, 706 http2=http2, 707 limits=limits, 708 ) 709 for key, proxy in proxy_map.items() 710 } 711 if mounts is not None: 712 self._mounts.update( 713 {URLPattern(key): transport for key, transport in mounts.items()} 714 )
File D:\news.venv\Lib\site-packages\httpx_client.py:750, in Client._init_proxy_transport(self, proxy, verify, cert, trust_env, http1, http2, limits) 740 def _init_proxy_transport( 741 self, 742 proxy: Proxy, (...) 748 limits: Limits = DEFAULT_LIMITS, 749 ) -> BaseTransport: --> 750 return HTTPTransport( 751 verify=verify, 752 cert=cert, 753 trust_env=trust_env, 754 http1=http1, 755 http2=http2, 756 limits=limits, 757 proxy=proxy, 758 )
File D:\news.venv\Lib\site-packages\httpx_transports\default.py:168, in HTTPTransport.init(self, verify, cert, trust_env, http1, http2, limits, proxy, uds, local_address, retries, socket_options) 155 if proxy is None: 156 self._pool = httpcore.ConnectionPool( 157 ssl_context=ssl_context, 158 max_connections=limits.max_connections, (...) 166 socket_options=socket_options, 167 ) --> 168 elif proxy.url.scheme in ("http", "https"): 169 self._pool = httpcore.HTTPProxy( 170 proxy_url=httpcore.URL( 171 scheme=proxy.url.raw_scheme, (...) 185 socket_options=socket_options, 186 ) 187 elif proxy.url.scheme in ("socks5", "socks5h"):
AttributeError: 'dict' object has no attribute 'url'
Thank you for the information.
According to the Traceback, it may relate to the proxy settings on your machine.
File D:\news.venv\Lib\site-packages\httpx_transports\default.py:168, in HTTPTransport.init(self, verify, cert, trust_env, http1, http2, limits, proxy, uds, local_address, retries, socket_options) 155 if proxy is None: 156 self._pool = httpcore.ConnectionPool( 157 ssl_context=ssl_context, 158 max_connections=limits.max_connections, (...) 166 socket_options=socket_options, 167 )--> 168 elif proxy.url.scheme in ("http", "https"): 169 self._pool = httpcore.HTTPProxy( 170 proxy_url=httpcore.URL( 171 scheme=proxy.url.raw_scheme, (...) 185 socket_options=socket_options, 186 ) 187 elif proxy.url.scheme in ("socks5", "socks5h"): AttributeError: 'dict' object has no attribute 'url'
It looks like it was unable to access the url property from the proxy object.
You can check you proxy settings and run the following command.
from httpx._utils import get_environment_proxies get_environment_proxies()
the code :
from httpx._utils import get_environment_proxies
get_environment_proxies()
The output :
{}
This code :
config = ld.get_config() config.set_param("logs.transports.file.enabled", True) config.set_param("logs.transports.file.name", "lseg-data-lib.log") config.set_param("logs.level", "debug") ld.open_session()
Gives this output errors :
AttributeError Traceback (most recent call last)Cell In[15], line 5 3 config.set_param("logs.transports.file.name", "lseg-data-lib.log") 4 config.set_param("logs.level", "debug")----> 5 ld.open_session()File ~\anaconda3\envs\refinitiv_env\lib\site-packages\lseg\data\_access_layer\session.py:92, in open_session(name, app_key, config_name) 89 set_default(new_session) 90 default_session = new_session---> 92 default_session.open() 94 return default_sessionFile ~\anaconda3\envs\refinitiv_env\lib\site-packages\lseg\data\_core\session\_session.py:374, in Session.open(self) 372 self._call_on_state("Session opening in progress") 373 self._config.on(configure.ConfigEvent.UPDATE, self._on_config_updated)--> 374 self._http_service.open() 375 is_opened = self._connection.open() 377 if is_opened:File ~\anaconda3\envs\refinitiv_env\lib\site-packages\lseg\data\_core\session\http_service.py:334, in HTTPService.open(self) 333 def open(self):--> 334 self._client.open()File ~\anaconda3\envs\refinitiv_env\lib\site-packages\lseg\data\_core\session\http_service.py:187, in HTTPClient.open(self) 183 proxies = self._session._proxies.get_proxy_for_httpx() 185 # httpx has its default Accept header and 186 # server wants application/json or nothing--> 187 self._client = get_httpx_client( 188 headers={"Accept": APPLICATION_JSON}, 189 limits=limits, 190 proxies=proxies, 191 ) 193 key = configure.keys.http_auto_retry_config 194 auto_retry_config = config.get(key, None)File ~\anaconda3\envs\refinitiv_env\lib\site-packages\lseg\data\_core\session\http_service.py:160, in get_httpx_client(proxies, **kwargs) 158 def get_httpx_client(proxies, **kwargs): 159 if httpx.__version__ >= "0.26.0":--> 160 client = httpx.Client(proxy=proxies, **kwargs) 161 else: 162 client = httpx.Client(proxies=proxies, **kwargs)File ~\anaconda3\envs\refinitiv_env\lib\site-packages\httpx\_client.py:697, in __init__(self, auth, params, headers, cookies, verify, cert, trust_env, http1, http2, proxy, mounts, timeout, follow_redirects, limits, max_redirects, event_hooks, base_url, transport, default_encoding) 682 self._mounts: typing.Dict[URLPattern, typing.Optional[BaseTransport]] = { 683 URLPattern(key): None 684 if proxy is None (...) 694 for key, proxy in proxy_map.items() 695 } 696 if mounts is not None:--> 697 self._mounts.update( 698 {URLPattern(key): transport for key, transport in mounts.items()} 699 ) 701 self._mounts = dict(sorted(self._mounts.items()))File ~\anaconda3\envs\refinitiv_env\lib\site-packages\httpx\_client.py:700, in <dictcomp>(.0) 0 <Error retrieving source code with stack_data see ipython/ipython#13598>File ~\anaconda3\envs\refinitiv_env\lib\site-packages\httpx\_client.py:750, in _init_proxy_transport(self, proxy, verify, cert, trust_env, http1, http2, limits) 749 def _transport_for_url(self, url: URL) -> BaseTransport:--> 750 """ 751 Returns the transport instance that should be used for a given URL. 752 This will either be the standard connection pool, or a proxy. 753 """ 754 for pattern, transport in self._mounts.items(): 755 if pattern.matches(url):File ~\anaconda3\envs\refinitiv_env\lib\site-packages\httpx\_transports\default.py:168, in __init__(self, verify, cert, trust_env, http1, http2, limits, proxy, uds, local_address, retries, socket_options) 160 except ImportError: # pragma: no cover 161 raise ImportError( 162 "Using SOCKS proxy, but the 'socksio' package is not installed. " 163 "Make sure to install httpx using `pip install httpx[socks]`." 164 ) from None 166 self._pool = httpcore.SOCKSProxy( 167 proxy_url=httpcore.URL(--> 168 scheme=proxy.url.raw_scheme, 169 host=proxy.url.raw_host, 170 port=proxy.url.port, 171 target=proxy.url.raw_path, 172 ), 173 proxy_auth=proxy.raw_auth, 174 ssl_context=ssl_context, 175 max_connections=limits.max_connections, 176 max_keepalive_connections=limits.max_keepalive_connections, 177 keepalive_expiry=limits.keepalive_expiry, 178 http1=http1, 179 http2=http2, 180 ) 181 else: # pragma: no cover 182 raise ValueError( 183 f"Proxy protocol must be either 'http', 'https', or 'socks5', but got {proxy.url.scheme!r}." 184 )AttributeError: 'dict' object has no attribute 'url
@mjabir
Is it possible to modify the ~\anaconda3\envs\refinitiv_env\lib\site-packages\lseg\data_core\session\http_service.py file at line: 160 to look like this?
def get_httpx_client(proxies, **kwargs): if httpx.__version__ >= "0.26.0": print("#### get_httpx_client:",proxies) client = httpx.Client(proxy=proxies, **kwargs) else: client = httpx.Client(proxies=proxies, **kwargs) return client
I added the print command to check the proxies value. It looks like to be an issue in the proxy settings on your environment.
When you ran the code, you will see the following text on the console.
Otherwise, you may need to downgrade the httpx to 0.24.1.
Thanks for your answer. I don't see the same path. See What I have in my case :
The path is lib not libs (~\anaconda3\envs\refinitiv_env\lib).