diff --git a/README.rst b/README.rst index ddf2c3b..531bea2 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -Python driver for ArangoDB +Python driver 0.2.3 for ArangoDB 2.1.1 -------------------------- Driver for **ArangoDB REST API** inrerface, `arangodb.org `_ @@ -10,7 +10,15 @@ Installation ************ :: - pip install arango + Download from repository + + wget https://github.com/appscluster/arango-python/archive/master.zip + + 7z x master.zip ( if you don't have 7z : sudo apt-get install p7zip-full ) + + cd arango-python-master + + python setup.py install Usage @@ -39,6 +47,75 @@ To start work with **ArangoDB** try following example:: for doc in conn.test_collection.query.execute(): print doc.id +To use **ArangoDB authentication via HTTP** try following example:: + + from requests.auth import HTTPBasicAuth + from arango.clients.requestsclient import RequestsClient + from arango.core import Connection + import sys + + def ARDBconnect(): + try: + # Prepare Login for ArangoDB + RequestsClient.config(auth=HTTPBasicAuth('arango_user', 'password')) + # Login for ArangoDB + db = Connection(db="test", client=RequestsClient) + # Connect to the appropriate DB + arango = db.version + print 'Connected to ArangoDB version: ', arango.version + return db + except Exception, e: + print "Error %d: %s" % (e.args[0], e.args[1]) + sys.exit(1) + + # Create ArangoDB connection handle + c = ARDBconnect() + c = c.collection + + # Create a new collection + c.test_collection.create() + # Add a document to the collection + c.test_collection.documents.create({"key": "value"}) + + # get first document + doc = c.test_collection.documents().first + # get document body + doc.body + + # get all documents in collection + for doc in c.test_collection.query.execute(): + print doc.id + +To **change or reset** arangodb **user** account **password**:: + + # In terminal run + arangosh + + # For improving security its a good idea to change the root account password + # Once in arangosh run the following commands + users = require("org/arangodb/users"); + users.update("root", "the_new_password", true); + users.reload(); + + quit + + # restart arangodb + /etc/init.d/arangodb restart + + +To enable arangodb **authentication** change the following 2 config files:: + + # 1. > /etc/arangodb/arangob.conf + [server] + disable-authentication = false + + # 2. > /etc/arangodb/arangod.conf + # disable authentication for the admin frontend + disable-authentication = no + + # restart arangodb for changes to take effect + /etc/init.d/arangodb restart + For more details please read `Documentation `_ @@ -50,12 +127,26 @@ Supported Python interpreters and versions: Supported **ArangoDB versions**: *1.4x* +Tested on **ArangoDB version**: *2.0.7, 2.1.0 and 2.1.1* + Developed by `Maksym Klymyshyn `_ +Forked by `Abdul Hamid `_ Changelog ********* +0.2.3 +~~~~~~ + + * default initialisation temporarily disabled and used RequestsClient.config directly instead. + * Added exception handling for status code 401 authentication failure to ArangoDB + +0.2.2 +~~~~~~ + + * Separated the use of the libraries available for opening URLs to use either PyCurl or Urllib2 and not to load both. + 0.2.1 ~~~~~~ diff --git a/arango/__init__.py b/arango/__init__.py index 6e24bc2..cdf02df 100644 --- a/arango/__init__.py +++ b/arango/__init__.py @@ -1,3 +1,5 @@ +''' +# temporarily disabled and RequestsClient.config used directly instead from arango.core import Connection @@ -10,3 +12,4 @@ def create(**kwargs): c = Connection() collection = c.collection +''' \ No newline at end of file diff --git a/arango/clients/__init__.py b/arango/clients/__init__.py index 598cb67..9c348f0 100644 --- a/arango/clients/__init__.py +++ b/arango/clients/__init__.py @@ -1,22 +1,33 @@ import sys import logging - -from .urllib2client import Urllib2Client - +logging.basicConfig() __all__ = ("Client",) - ISPY3 = sys.version_info >= (3, 0) -logger = logging.getLogger("arango.client") -Client = Urllib2Client - +logger = logging.getLogger("arango.clients") if ISPY3 is False: try: from .pycurlclient import PyCurlClient Client = PyCurlClient + except ImportError: + try: + logger.warning(u"PyCurl not available, trying Urllib2. %s", str(e)) + from .urllib2client import Urllib2Client + Client = Urllib2Client + except ImportError: + logger.warning(u"Urllib2 not available. %s", str(e)) except Exception as e: - logger.warning( - u"Sorry, can't import PyCurlClient. Reason: %s", str(e)) + logger.warning(u"No library available for opening URLs. %s", str(e)) +else: + try: + from .urllib2client import Urllib2Client + Client = Urllib2Client + except ImportError: +<<<<<<< HEAD + logger.warning(u"Urllib2 not available. %s", str(e)) +======= + logger.warning(u"Urllib2 not available. %s", str(e)) +>>>>>>> 73964918896a8bee82f15757c4e2a712ff38eadb diff --git a/arango/core.py b/arango/core.py index 45beb02..70e63e3 100644 --- a/arango/core.py +++ b/arango/core.py @@ -191,20 +191,29 @@ def __init__(self, url, response, args=None, expect_raw=False): self.message = "" self._data = None - try: - if expect_raw is False: - self.update({k: v - for k, v in - json.loads(response.text).items()}) - - except (TypeError, ValueError) as e: - msg = u"Can't parse response from ArangoDB:"\ + if (response.status_code==401): + raise Exception(401, 'Authentication Failed') + msg = u"Authentication Failed with ArangoDB:"\ u" {0} (URL: {1}, Response: {2})".format( - str(e), url, repr(response)) - + response.status_code, url, repr(response)) logger.error(msg) self.status = 500 self.message = msg + else: + try: + if expect_raw is False: + self.update({k: v + for k, v in + json.loads(response.text).items()}) + + except (TypeError, ValueError) as e: + msg = u"Can't parse response from ArangoDB:"\ + u" {0} (URL: {1}, Response: {2})".format( + str(e), url, repr(response)) + + logger.error(msg) + self.status = 500 + self.message = msg @property def data(self): diff --git a/setup.py b/setup.py index 13e59b0..2d04f20 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ os.system('python setup.py sdist upload') sys.exit() -VERSION = "0.2.1" +VERSION = "0.2.3" setup( name="arango", @@ -21,7 +21,7 @@ description="Driver for ArangoDB", author="Maksym Klymyshyn", author_email="klymyshyn@gmail.com", - url="http://arangodb-python-driver.readthedocs.org/en/latest/", + url="https://github.com/appscluster/arango-python", packages=["arango"], long_description=open("README.rst").read(), include_package_data=True,