如何解决使用 curl 命令下载用于日期范围的 API
我正在尝试从 FINRA 下载空头股票,我只能下载特定日期,如下所示。 curl -L -d "{ "compareFilters": [ { "compareType": "EQUAL","fieldName": "结算日期",**"fieldValue": " 2018-06-15"** } ],"limit" :5 } " -H "Content-Type: application/json" -H "Accept: application/json" -X POST https://api.finra.org/data/group/otcMarket/name/EquityShortInterest
但我正在尝试下载特定日期范围的数据,例如开始:2018-06-15,结束:2018-06-14。所以,我在字段值中尝试了以下代码。
卷曲-L -d "{ "compareFilters": [ { "compareType": "EQUAL","fieldName": "resolutionDate","fieldValue": ">2018-06-01 00:00:00&&https://api.finra.org/data/group/otcMarket/name/EquityShortInterest
然后,我把它转成json格式在python中运行。 当我运行日期范围如下的 json 格式时;
jsonout = response.json() 输出
我收到此错误:
{'statusCode': 400,'statusDescription': '错误请求','requestId': 'ab7af2fe-9189-4619-b0ca-ee368fb6e91d','message': '无法解析请求正文。'}
如果有人能帮助我,我将不胜感激,因为我对 curl 或 json 不太熟悉,而且编码不是我的职业生涯,因为我来自会计。
这是我转换后的json格式。
导入请求
标题 = { '内容类型':'应用程序/json', '接受':'应用程序/json', }
数据 = { '{ "compareFilters": [ { "compareType": "EQUAL","fieldValue": ">2018-06-01 00:00:00': '','
response = requests.post('https://api.finra.org/data/group/otcMarket/name/EquityShortInterest',headers=headers,data=data)
谢谢
解决方法
你可以试试:
curl -L -d '{ "compareFilters": [ { "compareType": "EQUAL","fieldName": " settlementDate","fieldValue": "2018-09-14 00:00:00" } ] } ' -H "Content-Type: application/json" -H "Accept: application/json" -X POST https://api.finra.org/data/group/otcMarket/name/EquityShortInterest
如果您使用curl
,建议您手动处理开始时间和结束时间。
您需要正确格式化正文,数据必须是字典。这应该有效:
import requests
import json
headers = {
'Content-Type': 'application/json','Accept': 'application/json',}
data = { "compareFilters": [ { "compareType": "EQUAL","fieldValue": "2018-09-14 00:00:00" } ] }
response =
requests.post('https://api.finra.org/data/group/otcMarket/name/EquityShortInterest',headers=headers,data=json.dumps(data))
print(response.content)