[Bug] TypeError returned when attempting to import OpenBB in Jupyter Notebook
kchander92 opened this issue · 14 comments
Describe the bug
After fully installing OpenBB in Jupyter Notebook using the pip installer using the command !pip install openbb[all]
, I attempted to run the command import openbb
, but it returned the following:
TypeError: 'type' object is not subscriptable
I'm not finding any resources online pertaining to this problem. Is there something different I have to do with the OpenBB platform installation? Thanks.
Desktop (please complete the following information):
- OS: Windows 11
- Python version 3.8.12
I believe this is because you are on 3.8. We have been slowly phasing out support for 3.8 with EOL later and we have not correctly updated our documentation to reflect this (support of 3.9 - 3.11)
The first one (the pip error message) - can be ignored.
The second one I have not seen before, but if you try running !pip install defusedxml==0.8.2rc2
, can you then import it?
Another thing to check is that your conda is up to date? Since you reinstalled it, I imagine it is, but I have seen some weird things.
Thanks James. I had trouble updating Python in my Conda environment, so I had to uninstall and reinstall Anaconda and now the Python version is 3.11.7.
The best way to do this is to create a new environment with the desired Python version.
There are potential PATH issues when using Anaconda Navigator and their Jupyter integration. It ignores the environment in favour of the "system" Python.
This is almost certainly the reason for the error in your second image.
https://github.com/OpenBB-finance/OpenBBTerminal/assets/101078824/84dff605-5fcf-4075-823f-ea6df47adae7
Looks like I just had to update Python once more to 3.11.8 and it worked. Thank you!
Now I seem to be having some trouble querying specific records. I set up API keys for FMP and Polygon on my OpenBB Platform account, but when I try to run the code below as copied directly from this example, I get the following OpenBB error:
At the end of the full error message, it says OpenBBError: Error in FMP request -> unknown error
. Do you know what could be causing this? If you would like for me to open a separate ticket for this issue, I can do that. Thanks.
Can you copy the whole error message for us?
If you enter this URL in a browser:
https://financialmodelingprep.com/api/v3/income-statement/TGT?period=quarter&limit=120&apikey=REPLACE_WITH_YOUR_KEY
Do you get results? I do know that FMP error messages are not being passed through, so I'm guessing that it is an entitlement issue.
Worth mentioning while we are here, I had to update some syntax for that:
data = (
obb.equity.fundamental.income("TGT", provider='fmp', limit=150, period="quarter")
.to_df()
)
shares = data["weighted_average_basic_shares_outstanding"]/1000000
Full error message below:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
File ~\anaconda3\Lib\site-packages\openbb_core\provider\query_executor.py:98, in QueryExecutor.execute(self, provider_name, model_name, params, credentials, **kwargs)
97 try:
---> 98 return await fetcher.fetch_data(params, filtered_credentials, **kwargs)
99 except Exception as e:
File ~\anaconda3\Lib\site-packages\openbb_core\provider\abstract\fetcher.py:85, in Fetcher.fetch_data(cls, params, credentials, **kwargs)
84 query = cls.transform_query(params=params)
---> 85 data = await maybe_coroutine(
86 cls.extract_data, query=query, credentials=credentials, **kwargs
87 )
88 return cls.transform_data(query=query, data=data, **kwargs)
File ~\anaconda3\Lib\site-packages\openbb_core\provider\utils\helpers.py:268, in maybe_coroutine(func, *args, **kwargs)
266 return cast(T, func(*args, **kwargs))
--> 268 return await func(*args, **kwargs)
File ~\anaconda3\Lib\site-packages\openbb_fmp\models\income_statement.py:244, in FMPIncomeStatementFetcher.aextract_data(query, credentials, **kwargs)
239 url = (
240 f"{base_url}/income-statement/{symbol}?"
241 f"period={query.period}&limit={query.limit}&apikey={api_key}"
242 )
--> 244 return await get_data_many(url, **kwargs)
File ~\anaconda3\Lib\site-packages\openbb_fmp\utils\helpers.py:139, in get_data_many(url, sub_dict, **kwargs)
125 """Get data from FMP endpoint and convert to list of schemas.
126
127 Parameters
(...)
137 Dictionary of data.
138 """
--> 139 data = await get_data(url, **kwargs)
141 if sub_dict and isinstance(data, dict):
File ~\anaconda3\Lib\site-packages\openbb_fmp\utils\helpers.py:79, in get_data(url, **kwargs)
78 """Get data from FMP endpoint."""
---> 79 return await amake_request(url, response_callback=response_callback, **kwargs)
File ~\anaconda3\Lib\site-packages\openbb_core\provider\utils\helpers.py:132, in amake_request(url, method, timeout, response_callback, **kwargs)
131 response = await session.request(method, url, **kwargs)
--> 132 return await response_callback(response, session)
133 finally:
File ~\anaconda3\Lib\site-packages\openbb_fmp\utils\helpers.py:66, in response_callback(response, _)
65 message = data.get("message", None) or data.get("error", "unknown error")
---> 66 raise RuntimeError(f"Error in FMP request -> {message}")
68 if "Error Message" in data:
RuntimeError: Error in FMP request -> unknown error
The above exception was the direct cause of the following exception:
OpenBBError Traceback (most recent call last)
File ~\anaconda3\Lib\site-packages\openbb_core\app\command_runner.py:328, in StaticCommandRunner._execute_func(cls, route, args, execution_context, func, kwargs)
327 try:
--> 328 obbject = await cls._command(
329 func=func,
330 kwargs=kwargs,
331 show_warnings=user_settings.preferences.show_warnings,
332 )
333 # pylint: disable=protected-access
File ~\anaconda3\Lib\site-packages\openbb_core\app\command_runner.py:250, in StaticCommandRunner._command(cls, func, kwargs, show_warnings)
249 with warnings.catch_warnings(record=True) as warning_list:
--> 250 obbject = await maybe_coroutine(func, **kwargs)
251 obbject.provider = getattr(
252 kwargs.get("provider_choices", None), "provider", None
253 )
File ~\anaconda3\Lib\site-packages\openbb_core\provider\utils\helpers.py:268, in maybe_coroutine(func, *args, **kwargs)
266 return cast(T, func(*args, **kwargs))
--> 268 return await func(*args, **kwargs)
File ~\anaconda3\Lib\site-packages\openbb_equity\fundamental\fundamental_router.py:158, in income(cc, provider_choices, standard_params, extra_params)
157 """Income Statement. Report on a company's financial performance."""
--> 158 return await OBBject.from_query(Query(**locals()))
File ~\anaconda3\Lib\site-packages\openbb_core\app\model\obbject.py:303, in OBBject.from_query(cls, query)
291 """Create OBBject from query.
292
293 Parameters
(...)
301 OBBject with results.
302 """
--> 303 return cls(results=await query.execute())
File ~\anaconda3\Lib\site-packages\openbb_core\app\query.py:72, in Query.execute(self)
70 query_executor = self.provider_interface.create_executor()
---> 72 return await query_executor.execute(
73 provider_name=self.provider,
74 model_name=self.name,
75 params={**standard_dict, **extra_dict},
76 credentials=self.cc.user_settings.credentials.model_dump(),
77 preferences=self.cc.user_settings.preferences.model_dump(),
78 )
File ~\anaconda3\Lib\site-packages\openbb_core\provider\query_executor.py:100, in QueryExecutor.execute(self, provider_name, model_name, params, credentials, **kwargs)
99 except Exception as e:
--> 100 raise OpenBBError(e) from e
OpenBBError: Error in FMP request -> unknown error
The above exception was the direct cause of the following exception:
OpenBBError Traceback (most recent call last)
Cell In[35], line 2
1 data = (
----> 2 obb.equity.fundamental.income("TGT", provider='fmp', limit=150, period="quarter")
3 .to_df()
4 )
6 shares = data["weighted_average_shares_outstanding"]/1000000
File ~\anaconda3\Lib\site-packages\openbb_core\app\static\utils\decorators.py:34, in validate.<locals>.decorated.<locals>.wrapper(*f_args, **f_kwargs)
32 @wraps(f)
33 def wrapper(*f_args, **f_kwargs):
---> 34 return validate_call(f, **dec_kwargs)(*f_args, **f_kwargs)
File ~\anaconda3\Lib\site-packages\pydantic\validate_call_decorator.py:58, in validate_call.<locals>.validate.<locals>.wrapper_function(*args, **kwargs)
56 @functools.wraps(function)
57 def wrapper_function(*args, **kwargs):
---> 58 return validate_call_wrapper(*args, **kwargs)
File ~\anaconda3\Lib\site-packages\pydantic\_internal\_validate_call.py:81, in ValidateCallWrapper.__call__(self, *args, **kwargs)
80 def __call__(self, *args: Any, **kwargs: Any) -> Any:
---> 81 res = self.__pydantic_validator__.validate_python(pydantic_core.ArgsKwargs(args, kwargs))
82 if self.__return_pydantic_validator__:
83 return self.__return_pydantic_validator__(res)
File ~\anaconda3\Lib\site-packages\openbb\package\equity_fundamental.py:1882, in ROUTER_equity_fundamental.income(self, symbol, period, limit, provider, **kwargs)
1544 @validate
1545 def income(
1546 self,
(...)
1558 **kwargs
1559 ) -> OBBject:
1560 """Income Statement. Report on a company's financial performance.
1561
1562 Parameters
(...)
1879 >>> obb.equity.fundamental.income(symbol="AAPL", period="annual", limit=5)
1880 """ # noqa: E501
-> 1882 return self._run(
1883 "/equity/fundamental/income",
1884 **filter_inputs(
1885 provider_choices={
1886 "provider": self._get_provider(
1887 provider,
1888 "/equity/fundamental/income",
1889 ("fmp", "intrinio", "polygon", "yfinance"),
1890 )
1891 },
1892 standard_params={
1893 "symbol": symbol,
1894 "period": period,
1895 "limit": limit,
1896 },
1897 extra_params=kwargs,
1898 )
1899 )
File ~\anaconda3\Lib\site-packages\openbb_core\app\static\container.py:20, in Container._run(self, *args, **kwargs)
18 def _run(self, *args, **kwargs) -> Any:
19 """Run a command in the container."""
---> 20 obbject = self._command_runner.sync_run(*args, **kwargs)
21 output_type = self._command_runner.user_settings.preferences.output_type
22 if output_type == "OBBject":
File ~\anaconda3\Lib\site-packages\openbb_core\app\command_runner.py:474, in CommandRunner.sync_run(self, route, user_settings, *args, **kwargs)
465 def sync_run(
466 self,
467 route: str,
(...)
471 **kwargs,
472 ) -> OBBject:
473 """Run a command and return the OBBject as output."""
--> 474 return run_async(self.run, route, user_settings, *args, **kwargs)
File ~\anaconda3\Lib\site-packages\openbb_core\provider\utils\helpers.py:280, in run_async(func, *args, **kwargs)
278 with start_blocking_portal() as portal:
279 try:
--> 280 return portal.call(partial(func, *args, **kwargs))
281 finally:
282 portal.call(portal.stop)
File ~\anaconda3\Lib\site-packages\anyio\from_thread.py:277, in BlockingPortal.call(self, func, *args)
264 def call(
265 self, func: Callable[..., Awaitable[T_Retval] | T_Retval], *args: object
266 ) -> T_Retval:
267 """
268 Call the given function in the event loop thread.
269
(...)
275
276 """
--> 277 return cast(T_Retval, self.start_task_soon(func, *args).result())
File ~\anaconda3\Lib\concurrent\futures\_base.py:456, in Future.result(self, timeout)
454 raise CancelledError()
455 elif self._state == FINISHED:
--> 456 return self.__get_result()
457 else:
458 raise TimeoutError()
File ~\anaconda3\Lib\concurrent\futures\_base.py:401, in Future.__get_result(self)
399 if self._exception:
400 try:
--> 401 raise self._exception
402 finally:
403 # Break a reference cycle with the exception in self._exception
404 self = None
File ~\anaconda3\Lib\site-packages\anyio\from_thread.py:217, in BlockingPortal._call_func(self, func, args, kwargs, future)
214 else:
215 future.add_done_callback(callback)
--> 217 retval = await retval
218 except self._cancelled_exc_class:
219 future.cancel()
File ~\anaconda3\Lib\site-packages\openbb_core\app\command_runner.py:462, in CommandRunner.run(self, route, user_settings, *args, **kwargs)
453 self._user_settings = user_settings or self._user_settings
455 execution_context = ExecutionContext(
456 command_map=self._command_map,
457 route=route,
458 system_settings=self._system_settings,
459 user_settings=self._user_settings,
460 )
--> 462 return await StaticCommandRunner.run(execution_context, *args, **kwargs)
File ~\anaconda3\Lib\site-packages\openbb_core\app\command_runner.py:377, in StaticCommandRunner.run(cls, execution_context, *args, **kwargs)
374 route = execution_context.route
376 if func := command_map.get_command(route=route):
--> 377 obbject = await cls._execute_func(
378 route=route,
379 args=args, # type: ignore
380 execution_context=execution_context,
381 func=func,
382 kwargs=kwargs,
383 )
384 else:
385 raise AttributeError(f"Invalid command : route={route}")
File ~\anaconda3\Lib\site-packages\openbb_core\app\command_runner.py:344, in StaticCommandRunner._execute_func(cls, route, args, execution_context, func, kwargs)
338 cls._chart(
339 obbject=obbject,
340 **kwargs,
341 )
343 except Exception as e:
--> 344 raise OpenBBError(e) from e
345 finally:
346 ls = LoggingService(
347 user_settings=user_settings, system_settings=system_settings
348 )
OpenBBError: Error in FMP request -> unknown error
If you enter this URL in a browser:
https://financialmodelingprep.com/api/v3/income-statement/TGT?period=quarter&limit=120&apikey=REPLACE_WITH_YOUR_KEY
Do you get results? I do know that FMP error messages are not being passed through, so I'm guessing that it is an entitlement issue.
No, the link didn't work. Does this mean I have to upgrade my subscription?
Worth mentioning while we are here, I had to update some syntax for that:
data = ( obb.equity.fundamental.income("TGT", provider='fmp', limit=150, period="quarter") .to_df() ) shares = data["weighted_average_basic_shares_outstanding"]/1000000
Sorry, I don't see the updates made to the code I posted?
No, the link didn't work. Does this mean I have to upgrade my subscription?
What does the error message in your browser say?
I've started using Polygon to provide the data now, and it seems to work better than FMP. Thank you!