Micah Morris
Micah Morris

Reputation: 74

Requests.get API data retrieval

Using Python 3.5.3 :: Anaconda 4.0.0 (64-bit) on Windows 10

The code below returns:

company_id,indicator_id

Please help me convert this request to the actual stock data provided by the link. The token in this code is not designated to any particular person, so it's fine to run it.

import requests

company_id = '320193,1418091'

url = 'https://api.usfundamentals.com/v1/indicators/xbrl?companies={{company_id}}&indicators=NetIncomeLoss&frequency=y&period_type=end_date&token=b-KCkr7xnSkmkhPm5N0iTA'


f = requests.get(url)

print (f.text)

Upvotes: 0

Views: 68

Answers (1)

ppp
ppp

Reputation: 1005

company_id in url is not getting evaluated. It works using str.format

import requests
company_id = '320193,1418091'

url = 'https://api.usfundamentals.com/v1/indicators/xbrl?companies={0}&indicators=NetIncomeLoss&frequency=y&period_type=end_date&token=b-KCkr7xnSkmkhPm5N0iTA'.format(company_id)

f = requests.get(url)

print (f.text)

Upvotes: 2

Related Questions