我正在尝试使用 SODA API 以编程方式删除 Socrata 数据集中的所有行。我不想删除数据集本身,因为那样我就有很多工作来重建它。对数千行执行此操作也非常慢。
以前,我在每一行上慢慢迭代,删除每一行,直到Twitter 上有人建议做一个没有行的 Upsert。我相信我实现了这个并且它有效,但现在它没有。
这是相关的代码:
headers = {'X-App-Token': config.app_token}
headers['Content-Type'] = 'application/json'
r = requests.put(config.dataset + '.json', data='[ ]', headers=headers, auth=config.auth)
print r.status_code, r.text
输出是:
200 {
"By RowIdentifier" : 0,
"Rows Updated" : 0,
"Rows Deleted" : 0,
"Rows Created" : 0,
"Errors" : 0,
"By SID" : 0
}
(所以我认为可以肯定地说问题与身份验证、授权等无关?我的其他插入行的功能工作正常,因此错误的数据集 URL 或其他任何东西也不是问题。)
我也查询了前后的行数,没有变化。还是几千行。
据我所知,我正在关注批量替换行的 API 文档。
我唯一能想到的是,由于一个错误,我有多行具有相同的 rowid。
编辑
以下是一些重复的行标识符:
rowid
绝对设置为行标识符:
现在考虑到行标识符应该“基本上与主键的行为方式相同”,我开始怀疑这是一个错误,还是出现了可怕的错误?发布代码如下所示:
def publishDataset(rows):
r = requests.post(config.dataset, data=simplejson.dumps(rows), headers = headers, auth=config.auth)
j = r.json()
print
if r.status_code != 200:
raise RuntimeError ( "%d Socrata error: %s" % (r.status_code, j['message']))
return j