Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Using API Keys #43

Open
Open

Description

@dennismonsewicz

Can someone give an example on using Cloudant API Keys to connect?

Activity

  1. garbados commented on Jun 5, 2014

    @garbados
    import cloudant
    
    account = cloudant.Account(USERNAME, auth=(API_KEY, API_SECRET))

    Let me know if that doesn't work :)

  2. dennismonsewicz commented on Jun 10, 2014

    @dennismonsewicz
    Author

    The code seems to be working, but when I try to iterate over all the documents in the DB, I am getting this error:

    {u'reason': u'_reader access is required for this request', u'error': u'unauthorized'}

    The API key I am using is setup to be an admin on the account

  3. dennismonsewicz commented on Jun 10, 2014

    @dennismonsewicz
    Author

    Another question, I am using the library to incorporate with a CRUD controller in a Flask app...

    I am attempting to DRY up some of my code and here is what I have so far:

    class WorkflowsCloudant(cloudant.Account):
        def __init__(self):
            super(WorkflowsCloudant, self).__init__(settings.COUCH_DB_ACCOUNT_NAME,
                                                    auth=(settings.COUCH_PUBLIC_KEY, settings.COUCH_PRIVATE_KEY))
            self._set_database()
    
        def _set_database(self):
            return self.database(settings.COUCH_DB_NAME)
    
    
    
    @blueprint.route('/<workflow_id>')
    def get_single_workflow(account_id, workflow_id):
        account = WorkflowsCloudant()
        # db = account.database(settings.COUCH_DB_NAME)
        doc = account.document(workflow_id)
        resp = doc.get().json()
    
        if resp['account_id'] != account_id:
            return error_helpers.forbidden('Invalid Account')
    
        return jsonify(resp)

    For some reason when I try to access account.document() the error I am getting is: AttributeError: 'WorkflowsCloudant' object has no attribute 'document'

    Sorry for my ignorance, I am a Python newb

  4. janakmayer commented on Mar 19, 2015

    @janakmayer

    I have the same issue as dennismonsewicz - I can authenticate using

    account = cloudant.Account(USERNAME, auth=(API_KEY, API_SECRET))
    db= account.database('my-database')

    and I can then read and write individual docs to the db without a problem. However when I try to iterate over all docs with
    db.all_docs()
    I get the same error:
    {u'reason': u'_reader access is required for this request', u'error': u'unauthorized'}

  5. janakmayer commented on Mar 19, 2015

    @janakmayer

    I just created a pull request to fix this: #53

    In the mean time, a solution that works is to pass the authorization tuple directly into the all_docs() method:

    auth = (api_key, api_secret)
    DB.all_docs(auth=auth)
  6. ayushidalmia commented on Aug 22, 2016

    @ayushidalmia

    On line:
    account = cloudant.Account(USERNAME, auth=(API_KEY, API_SECRET))

    I get the error:
    AttributeError: 'module' object has no attribute 'Account'

  7. TheBatAss commented on Mar 30, 2017

    @TheBatAss

    I get the same error as @ayushidalmia, anyone resolved this?

  8. rajlath commented on Jun 29, 2017

    @rajlath

    try this
    from cloudant.client import Cloudant
    account = Cloudant(USERNAME, auth=(API_KEY, API_SECRET)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions