Python SDK on Ubuntu 14

Finally managed to make it working… not perfect, but fair enough.

Had to install alternative Python 2.7.13, in a way not to clash with system python installation.
Compilation/installation had some hitches - did not go smooth.

Hints: https://tecadmin.net/install-python-2-7-on-ubuntu-and-linuxmint/

most helpful: sudo make altinstall

after that:

$ /usr/local/bin/python2.7 -m pip install couchbase
Requirement already satisfied: couchbase in /home/xxx/.local/lib/python2.7/site-packages

nice, fire Python:

$ /usr/local/bin/python2.7
Python 2.7.13 (default, Jul 30 2017, 14:01:53) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.

let’s try:

>>> from couchbase.bucket import Bucket
>>>

OK so far… start server (another terminal…)

$ sudo service couchbase-server start
* Started couchbase-server

continue with python …

>>> cb = Bucket('couchbase://localhost/default')
>>> cb.upsert('u:king_arthur', {'name': 'Arthur', 'email': 'kingarthur@couchbase.com', 'email': 'kingarthur@couchbase.com', 'interests': ['Holy Grail', 'African Swallows']})
OperationResult<rc=0x0, key=u'u:king_arthur', cas=0x14d6215254d60000>

worked.

Indexing did not work. Failed.

(checked in admin, index was already created, perhaps I created it already while tinkering with administration, I think deep down error also suggests that)

>>> cb.n1ql_query('CREATE PRIMARY INDEX ON default').execute()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xxx/.local/lib/python2.7/site-packages/couchbase/n1ql.py", line 365, in execute
    for _ in self:
  File "/home/xxx/.local/lib/python2.7/site-packages/couchbase/n1ql.py", line 389, in __iter__
    raw_rows = self.raw.fetch(self._mres)
couchbase.exceptions.HTTPError: <RC=0x3B[HTTP Operation failed. Inspect status code for details], HTTP Request failed. Examine 'objextra' for full result, Results=1, C Source=(src/http.c,140), OBJ=ViewResult<rc=0x3B[HTTP Operation failed. Inspect status code for details], value={u'status': u'errors', u'errors': [{u'msg': u'GSI CreatePrimaryIndex() - cause: Index default.#primary already exists', u'code': 5000}], u'results': [], u'metrics': {u'elapsedTime': u'2.32618749s', u'executionTime': u'2.266885629s', u'resultSize': 0, u'resultCount': 0, u'errorCount': 1}, u'requestID': u'7d425eeb-7b5d-4b23-9c87-9cbfee0f73ff', u'signature': None}, http_status=500>>

Let’s Query:

>>> from couchbase.n1ql import N1QLQuery
>>> row_iter = cb.n1ql_query(N1QLQuery('SELECT name FROM default WHERE $1 IN interests', 'African Swallows'))
>>> row_iter
<couchbase.n1ql.N1QLRequest object at 0x7fc6b83bff50>
>>> for row in row_iter: print row
... 
{u'name': u'Arthur'}
>>>

Good. Worked. Enough for fiddling around.

Any suggestions on how it could have been better are welcome