简体   繁体   中英

Cannot connect to the Apache CouchDb using Python - InvalidURL Nonnumeric port Exception

Using Python, I've been trying to connect to the couchdb where I have the company database.

import couchdb

    try:
        username = "admin"
        password = "mypassword"

        couchdb_server = couchdb.Server("http://%s:%s@localhost:5984/" % (username, password))
        
        print(couchdb_server['company'])

    except Exception as ex:
        print(str(ex))

When I run the code above, I end up with the following exception:

ex={InvalidURL}nonnumeric port: '...'

Any idea why I cannot connect my couchdb server and see all my databases including the company database?

I've finally figured it out from here . It works now. Don't trust the traditional python-couchdb tutorials, they apply the authorization the way I was doing.

try:
    username = "admin"
    password = "mypassword"
    host = "localhost:5984"

    couchdb_server = couchdb.Server('http://'+host)

    couchdb_server.resource.credentials = (username, password)

    db = couchdb_server["company"]

    ...
    ...
    ...
    
except Exception as ex:
    print(str(ex))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM