~thisfred/desktopcouch/lp-673641

« back to all changes in this revision

Viewing changes to desktopcouch/application/pair/couchdb_pairing/couchdb_io.py

Ah HTTP error (say, from proxy server) may not return JSON document so we can't depend on being able to decode one.  Catch and log those errors.

python-couchdb prepends its own "/" in requests, so our use of them can cause errors when talking to remote hosts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import uuid
25
25
import datetime
26
26
from itertools import cycle
 
27
try:
 
28
    import simplejson as json
 
29
except ImportError:
 
30
    import json
27
31
 
28
32
from desktopcouch.application import local_files
29
33
from desktopcouch.application.platform import find_port
150
154
                "Got list of databases from %s:\n    %s",
151
155
                couchdb_server, all_dbs)
152
156
        else:
153
 
            all_dbs = set(couchdb_server.resource.get(
154
 
                '/_all_dbs', user_id=user_id)[1])
 
157
            code, _, res = couchdb_server.resource.get('_all_dbs',
 
158
                                                       user_id=user_id)
 
159
            if code != 200:
 
160
                logging.error("%s/_all_dbs?user_id=%s HTTP%d", couchdb_server,
 
161
                              user_id, code)
 
162
                return set()
 
163
 
 
164
            all_dbs = set(json.load(res))
155
165
            logging.debug(
156
 
                "Got list of databases from %s/_all_dbs?user_id=%s:\n    %s",
 
166
                "Got list of databases from %s/_all_dbs?user_id=%s:\n    %r",
157
167
                couchdb_server, user_id, all_dbs)
158
168
 
159
169
    except socket.error:
269
279
        else:
270
280
            server.DesktopDatabase(target_database, create=True, uri=local_uri,
271
281
                                   ctx=ctx)
272
 
        logging.debug("db exists, and we're ready to replicate")
 
282
        logging.debug("%r exists. Ready to replicate.", target_database)
273
283
    except:                             # pylint: disable=W0702
274
284
        logging.exception(
275
285
            "can't create/verify %r %s:%d  oauth=%s", target_database,