通过使用 python 代码,我尝试从 json 文件读取数据并通过 API 上传。但是我收到 HTTP 错误 5000。以下是我的代码:
url = 'http://sipdev1.vbi.vt.edu:8080/EpiViewer/epiviewer/services/uploadGraphData'
for i in json_file_name:
json_data = open (i, 'r')
lines=json_data.readlines()
req = urllib2.Request(url)
req.add_header('Content-Type','application/json')
data = json.dumps(lines)
response = urllib2.urlopen(req,data)
这是错误:
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error
输入文件示例:
{
"username": "xxxxx",
"password": "yyyyy",
"timeSeriesName": "Liberia_01-18-2015",
"dataType": "Cases",
"plotType": "Cumulative",
"filename": "C_C.csv",
"dateFormat": "MM-dd-yy",
"forecastedOn": "01/18/2015",
"visibility": "Public",
"data": {
"01-25-2015":"26 38 14",
"02-01-2015":"22 33 11",
"02-08-2015":"19 32 6",
"02-15-2015":"17 32 2",
"02-22-2015":"15 18 12",
"03-01-2015":"14 26 2"
}
}
我认为代码无法正确解析我的输入文件。您对解决方案有什么想法吗?
最佳答案
您的文件已经编码为 JSON。您不需要再次对其进行编码。发送原样文件:
for name in json_file_name:
with open(name) as json_data:
data = json_data.read()
req = urllib2.Request(url, data, {'Content-Type': 'application/json'})
response = urllib2.urlopen(req)
关于Python数据上传错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30384874/