Skip to content

AttributeError: 'str' object has no attribute 'extend' when using custom connect_kwargs and key_filename option #2007

Description

@joeydumont

When using a custom connect_kwargs with a key_filename option, like so:

    config = fabric.config.Config()
    print("Connecting with ssh/config")
    with fabric.Connection(
        host=instancePrivateIp,
        user='ec2-user',
        config=config,
        connect_kwargs={
            "key_filename": keyFileName,
        }) as c_instance:

I get an AttributeError:

  File "/home/dumontj/Projects/ami-builder/ami_builder/customization.py", line 26, in do_bash_customization
    "key_filename": keyFileName,
  File "/home/dumontj/.local/share/virtualenvs/ami-builder-jbdgQc96/lib/python3.7/site-packages/fabric/connection.py", line 450, in __init__
    self.connect_kwargs = self.resolve_connect_kwargs(connect_kwargs)
  File "/home/dumontj/.local/share/virtualenvs/ami-builder-jbdgQc96/lib/python3.7/site-packages/fabric/connection.py", line 490, in resolve_connect_kwargs
    connect_kwargs["key_filename"].extend(
AttributeError: 'str' object has no attribute 'extend'

The documentation specifies that key_filename should be given as a string, but I found that it works if you actually give it a list:

    with fabric.Connection(
        host=instancePrivateIp,
        user='ec2-user',
        config=config,
        connect_kwargs={
            "key_filename": [keyFileName,],
        }) as c_instance:

If this is the wanted syntax, I can update the documentation through a PR (see https://github.com/fabric/fabric/blob/2.0/fabric/connection.py#L234). Otherwise I could change fabric/connection.py to check whether there is already an entry, then transform it into a list if necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions