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

SFTPStorage silently swallows exception for connection failures #835

Closed
pansapiens opened this issue Feb 11, 2020 · 2 comments
Closed

SFTPStorage silently swallows exception for connection failures #835

pansapiens opened this issue Feb 11, 2020 · 2 comments

Comments

@pansapiens
Copy link
Contributor

Specifically:

except Exception as e:
print(e)

Wouldn't it be better to raise the exception to allow it to be handled by calling code ?
It's been causing issues in my use case, since there's no easy way to handle connection failure to SFTP servers that are offline.

eg attempting to connect to a server that doesn't exist:

from storages.backends.sftpstorage import SFTPStorage

params = dict(port=22,
              username='root',
              password='hunter')
storage = SFTPStorage(host='does-not.exist-domain.example.com', params=params)
storage._connect()
storage.sftp

Outputs:

[Errno -2] Name or service not known
[Errno -2] Name or service not known

rather than raising an exception.

I can work around this issue by calling these private methods before attempting to use the SFTPStorage instance, but it's more of a hacky workaround:

storage._connect()  # so that ._ssh exists
 # will raise an exception if connection fails
storage._ssh.connect(storage._host, **storage._params)
@jschneier
Copy link
Owner

Yep. If you open a PR I will merge it.

Also, think you mean hunter2 :)

@pansapiens
Copy link
Contributor Author

Will do. Not sure what you mean by ******* though :)

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

2 participants