How to use the datacite.__init__.DataciteAPIException function in datacite

To help you get started, we’ve selected a few datacite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github open-machine-learning / mldata / datacite / __init__.py View on Github external
    @param method: http method ('GET' or 'POST')
    @type location: string
    @return: response type and message
    @rtype: tuple of int and string
    """
    h = httplib2.Http(disable_ssl_certificate_validation=True)
    auth_string = base64.encodestring(settings.DATACITE_USERNAME + ':' + settings.DATACITE_PASSWORD)
    
    response, content = h.request(settings.DATACITE_API_URL + req,
                                  method,
                                  body = body_unicode.encode('utf-8'),
                                  headers={'Content-Type':'text/plain;charset=UTF-8',
                                           'Authorization':'Basic ' + auth_string})
    
    if (response.status > 201):
        raise DataciteAPIException(response.status, content.decode('utf-8'))
    return response.status, content.decode('utf-8')