使用PAXPAND_CREATE API调用Python中的package_create api呼叫创建包装



我正在尝试将带有资源的数据包上传到CKAN(通过Python(。我可以在没有"资源"的情况下成功上传包裹,但是我不断遇到此错误: 'message': "Only lists of dicts can be placed against subschema ('resources',), not <type 'list'>"

我尝试过多次重新格式化python词典,并在词典上使用了json.dumps((,但是我在调用API时遇到了JSON错误。

test_dict = 
      {
      'title': 'title of my dataset',
      'start': '2018-09-15 00:00:00',
      'end': '2018-09-20 00:00:00',
      'fact': 'interesting fact',
      'ReportNo': 1234,
      'type': 'data',
      'notes': ' ',
      'owner_org': 'Org',
      'maintainer': 'Me',
      'name': 'Test package for S3',
      'resources': [
          {
                    'package_id': '',
                    'url': 'https://s3-test-bucket/test.txt',
                    'name': 'S3 URL testing',
                    'description': 'does description work?'
                    }
      ]
}
response = requests.post(url, test_dict, headers=auth)
response.json()

期望:'成功':'true'

获取:'message':"只能针对subschema('resources',(,而不是", '__Type':'完整性错误'

请有人解释正确的Python词典格式吗?最好与示例。

谢谢!

我根据此帖子找到了答案:使用CKAN API创建CKAN数据集和Python请求库

这是我正在使用的代码:

    headers = json.loads(open('API_KEY','rb').read())
    headers['Content-Type'] = 'application/x-www-form-urlencoded'
    ckan = 'https://yourckanwebsite/api/3/action/'
    uri = ckan + 'package_create'
    data_dict = urllib.parse.quote(json.dumps(test_dict))
    response = requests.post(uri, data=data_dict, headers=headers)
    response.json()

最新更新