Skip to content

@mammadori /ckanclient_fix.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
How to use CkanClient with CKAN 1.8 for file upload using ckan_client.upload_file(). The fixed issue was about handling HTTP Redirects, the original version returns an "obscure" «('', 'Found')» "warning" instead. The problem was first reported here: http://lists.okfn.org/pipermail/ckan-dev/2012-August/002816.html
def _post_multipart(self, selector, fields, files):
'''Post fields and files to an http host as multipart/form-data.
:param fields: a sequence of (name, value) tuples for regular form
fields
:param files: a sequence of (name, filename, value) tuples for data to
be uploaded as files
:returns: the server's response page
'''
from urlparse import urljoin, urlparse
content_type, body = self._encode_multipart_formdata(fields, files)
headers = self._auth_headers()
url = urljoin(self.base_location + urlparse(self.base_location).netloc, selector)
req = requests.post(url, data=dict(fields), files={files[0][0]: files[0][1:]}, headers=headers)
return req.status_code, req.error, req.headers, req.text
import ckanclient
# FIXME: no monkey patching here
ckanclient.CkanClient._post_multipart = _post_multipart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.