我正在使用python请求库从API获取数据。我的代码如下。我可以从API打印JSON响应: 但无法保存或读取csv响应。我究竟做错了什么?最有可能是我处理回应的方式。我签出了文档中的“请求”,但没有直接链接。
CSV响应代码。
import requests
import alpha_vantage
import json
API_URL = "https://www.alphavantage.co/query"
data = {
"function": "TIME_SERIES_DAILY_ADJUSTED",
"symbol": 'PFC.NS',
"outputsize": "full",
"datatype": "csv",
"apikey": "key_here",
}
response = requests.get(API_URL, params=data)
print(response.csv())
JSON代码:
import requests
import alpha_vantage
import json
API_URL = "https://www.alphavantage.co/query"
data = {
"function": "TIME_SERIES_DAILY_ADJUSTED",
"symbol": 'PFC.NS',
"outputsize": "full",
"datatype": "json",
"apikey": "key_here",
}
response = requests.get(API_URL, params=data)
print(response.json())