Python使用“ POST”方法通过API提取数据

时间:2018-08-28 21:27:26

标签: python api post

我正在从http://www.nfib-sbet.org/developers/中提取数据。我无法在网站上复制该演示

示例API请求:

方法:开机自检 响应内容类型:application / json 参数内容类型:application / json 网址:

http://open.api.nfib-sbet.org/rest/sbetdb/_proc/getIndicators

请求正文:

{
 "app_name": "sbet",
 "params": [
 { "name": "minYear", "param_type": "IN", "value": 2010 },
 { "name": "minMonth", "param_type": "IN", "value": 6 },
 { "name": "maxYear", "param_type": "IN", "value": 2010 },
 { "name": "maxMonth", "param_type": "IN", "value": 12 },
 { "name": "indicator", "param_type": "IN", "value": "OPT_INDEX" }
 ]
 }

所以我想出了这段代码来提取数据:

import pandas as pd
import time
import requests
import urllib
import json
import re
import datetime
import os
import sys
import glob
import json



params = {
 "app_name": "sbet"}
data = {
"minYear": 2010 ,
"minMonth": 6 ,
"maxYear": 2010 ,
"maxMonth": 12 ,
"indicator": "OPT_INDEX"
}
headers = {'Content-type': 'application/json'}


This_URL = "http://open.api.nfib-sbet.org/rest/sbetdb/_proc/getIndicators"
# Make a get request with the parameters.
requests.post(url=This_URL, params=params, data=json.dumps(data),headers = headers)

但是它不断返回

<Response [500]>

0 个答案:

没有答案