ckan / ckan/ckanapi

Problems with package_create in api 2.5.2

Open
#94 12 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
212
Forks
81
PR merge metrics
No merged PRs in 30d

Description

I have a script which seeds CKAN instances with groups, organizations, datasets and resources After creating resources it downloads the resource dictionary and then uploads a file (I coudl not find a way to do it in one step). My script works perfectly when run against CKAN 2.4.0 but is failing when I run it against 2.5.2. Was there an API change between versions that effects ckanapi?

In the newer version it appears that the package is not being returned as a dictionary in this line:
dataset = ckan.action.package_create

When I attempt to look at dataset with pprint it returns -1.

Otherwise it fails with this error:
Traceback (most recent call last):
File "C:/Users/akoebrick/PycharmProjects/NG911/seed.py", line 160, in
resourceId = dataset['resources'][0]['id']
TypeError: 'int' object has no attribute '**getitem**'

Here is my relevant code:

```
# Now add the packages
##############################
for package in datasets:
packageTitle = package['title'] + " - " + countyPlain
packageName = munge(package['title'])

#Add county name to packageName to make it unique
packageName = packageName + "-" + countyName
#Add the datasets
try:
dataset = ckan.action.package_create(name=packageName, title=packageTitle, notes=package['notes'], groups=package['group'],resources=package['resources'], owner_org=orgId)
except:
e = sys.exc_info()[0]
print "Error: %s : " %e
exc_type, exc_value, exc_traceback = sys.exc_info()
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
print ''.join('!! ' + line for line in lines) # Log it or whatever here

#Update the resource so it is a file upload rather than a url. Does not seem to be possible in initial loop
resourceId = dataset['resources'][0]['id']
fileName = dataset['resources'][0]['name']
fileName = 'data/' + fileName
resourceUpdate = ckan.action.resource_update(id=resourceId, upload=open(fileName, "rb"))
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.