Skip to content

Commit

Permalink
Authenticate requests for files uploaded to CKAN
Browse files Browse the repository at this point in the history
If the resource url_type is uploaded, we send the Authenticatio header
with the request, as we are actually pointing to a CKAN controller. If
we don't provide it, the request will fail as CKAN will return a 401
  • Loading branch information
amercader committed Jan 23, 2014
1 parent 47fd01f commit 2394e81
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions datapusher/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,14 @@ def push_to_datastore(task_id, input, dry_run=False):
# fetch the resource data
logger.info('Fetching from: {0}'.format(resource.get('url')))
try:
response = urllib2.urlopen(resource.get('url'),
timeout=DOWNLOAD_TIMEOUT)
request = urllib2.Request(resource.get('url'))

if resource.get('url_type') == 'upload':
# If this is an uploaded file to CKAN, authenticate the request,
# otherwise we won't get file from private resources
request.add_header('Authorization', api_key)

response = urllib2.urlopen(request, timeout=DOWNLOAD_TIMEOUT)
except urllib2.HTTPError as e:
raise util.JobError('Invalid HTTP response: %s' % e)
except urllib2.URLError as e:
Expand Down

0 comments on commit 2394e81

Please sign in to comment.