Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joeydumont opened this issue Aug 31, 2019 · 12 comments

Comments

@joeydumont
Copy link

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.

@boweevil
Copy link

I'm seeing the same issue on 2.5. However, using a list works.

@adq
Copy link

adq commented Oct 28, 2019

Same problem. Looks like it could be a silly bug to me, so pinning to 2.4.0 till we hear more from upstream.

@m4g005
Copy link

m4g005 commented Nov 11, 2019

I get the same problem when host is set to a DNS name. When set to an IP, the exception doesn't occur.
E.g.:

{'host': '127.0.0.1', 'user': 'MyUser', 'connect_kwargs': {'key_filename': '/Users/MyUser/.ssh/MyPem.pem'}} # <- Works
{'host': 'some.dns.name', 'user': 'MyUser', 'connect_kwargs': {'key_filename': '/Users/MyUser/.ssh/MyPem.pem'}} # <- Doesn't work

@BISMIFATHIMANASAR
Copy link

face_caches[self.face_img_paths[i].stem] = faces
AttributeError: 'str' object has no attribute 'stem'
i got this error. can anyone suggest me a solution

@danmichaelo
Copy link

danmichaelo commented Feb 11, 2020

Someone else made a PR to change the docs in Sep 2019, but not merged yet (Feb 2020): #2014

@fmors
Copy link

fmors commented Apr 29, 2020

This happens to me as well... and also, I think it would be important to be able to set if I only want to connect using the key_filename provided, instead of using the ssh_config info.

@laver0ck
Copy link

It is an error in docs. key_filename expects a list.

c = Connection(
    host="hostname",
    user="admin",
    connect_kwargs={
        "key_filename": ["/home/myuser/.ssh/private.key"],
    },
)

@vardhmanandroid2015
Copy link

Providing key file name within list worked.. Thanks
@laver0ck for pointing this...

@bdmorin
Copy link

bdmorin commented Apr 15, 2022

Documentation is still wrong, what an infuriating waste of 2 hours. lol

@vardhmanandroid2015
Copy link

i know it is quite frustrating but it is an open source so we need to be little patient with such issues.... Is there anything I can do to update document so others will not get frustrated with this......

@bitprophet
Copy link
Member

#1924 is one stab at solving this. Will merge it or something based on it shortly.

@bitprophet
Copy link
Member

2.7.1 is out with the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests