0

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?

user3288051
  • 574
  • 1
  • 11
  • 28
  • It sounds like the password or part of the password (if it contains a :) is being treated as a port. Can you add details of what python library/version you are using for couchdb? – lossleader Dec 01 '20 at 21:39
  • Does your username or password contain an `@` symbol that would invalidate the URL? If so, try URL-encoding those values. – Jonathan Hall Dec 03 '20 at 06:01

1 Answers1

1

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))
user3288051
  • 574
  • 1
  • 11
  • 28