question

jbishop avatar image
1 Like"
jbishop asked ·

type Argument in Python API calls

Has anyone had issues with the type argument in Python when making API calls? Whenever I use it, the argument modifies the __builtins__.type variable. I've worked around it by creating a variable that stores type(), but Intrinio said they haven't had anyone else experience the issue. I think that the "type" argument in the API should be changed to "kind" or something similar.


To reproduce easily, just copy and paste the following into a Jupyter notebook, then try to check the type of a variable.


from __future__ import print_function
import time
import intrinio_sdk
from intrinio_sdk.rest import ApiException
from pprint import pprint

intrinio_sdk.ApiClient().configuration.api_key['api_key'] = 'YOUR_API_KEY'

company_api = intrinio_sdk.CompanyApi()

identifier = 'AAPL' # str | A Company identifier (Ticker, CIK, LEI, Intrinio ID)
tag = 'marketcap' # str | An Intrinio data tag ID or code (<a href='https://data.intrinio.com/data-tags'>reference</a>)
frequency = 'daily' # str | Return historical data in the given frequency (optional) (default to daily)
type = '' # str | Return historical data for given fiscal period type (optional)
start_date = '2018-01-01' # date | Return historical data on or after this date (optional)
end_date = '' # date | Return historical data on or before this date (optional)
sort_order = 'desc' # str | Sort by date `asc` or `desc` (optional) (default to desc)
page_size = 100 # int | The number of results to return (optional) (default to 100)
next_page = '' # str | Gets the next page of data from a previous API call (optional)

try:
  api_response = company_api.get_company_historical_data(identifier, tag, frequency=frequency, type=type, start_date=start_date, end_date=end_date, sort_order=sort_order, page_size=page_size, next_page=next_page)
  pprint(api_response)
except ApiException as e:
  print("Exception when calling CompanyApi->get_company_historical_data: %s\r\n" % e)
pythonsdk
· 1
10 |600 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

I have been able to reproduce the error, and I will be looking into it further.

0 Likes 0 · ·

1 Answer

· Write an Answer
mkelly avatar image
0 Likes"
mkelly answered ·

The issue is one of scope. Setting the type variable changes the immediate definition of "type", so to use the built-in type check function you need to specify that you are using __builtins__.type. For example to check what type the api_response variable is, use:

__builtins__.type(api_response)
· Share
10 |600 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.