I just use pylxd, how to update cert=('/path/to/client.crt', '/path/to/client.key') on another server

client = Client(
...      endpoint='http://216.xx.xx.202:8443',
...      cert=('lxd.crt',
... 'lxd.key'),
...      verify=False)
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pylxd/client.py", line 318, in __init__
    response = self.api.get()
  File "/usr/local/lib/python2.7/dist-packages/pylxd/client.py", line 158, in get
    response = self.session.get(self._api_endpoint, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 542, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 417, in send
    self.cert_verify(conn, request.url, verify, cert)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 251, in cert_verify
    "invalid path: {}".format(conn.cert_file))
IOError: Could not find the TLS certificate file, invalid path: lxd.crt

I am a novice in pylxd. I don’t know how to create client.crt and client.key on LXD. I tried many times but failed to use it. I used snap to install LXD. I hope you can help me, thank you very much.

The easiest way to hint lxc into creating a TLS cert is probably to run this command:

$ lxc remote add foo https://127.0.0.1:8443
Generating a client certificate. This may take a minute...
Error: Get "https://127.0.0.1:8443": Unable to connect to: 127.0.0.1:8443 ([dial tcp 127.0.0.1:8443: connect: connection refused])

Don’t mind the connection refused error, that was just to have the client cert generated. You can now find the files in your home ~/snap/lxd/common/config/client.*.

Please note that recent/current pylxd versions no longer support Python 2.7.

Thank you for your answer, but still unable to connect IOError: Could not find the TLS certificate file, invalid path: ~/snap/lxd/common/config/client.crt

I changed the password and created the client by executing lxc config set core.trust_password=xxxx, this file exists in ~/snap/lxd/common/config/

FYI, when you provide the path to your client.crt and .key to pylxd, you must use a full path, not one with ~ in it. If that doesn’t help, please share the error and the code triggering it.