I am trying to move my Django file storage to an external server, connected via ethernet to a small local network. This local network is not connected to the internet. I am using django-storages SFTPStorage for my file fields now. The server runs fine, but upon a file upload attempt, I get the following error:
Performing system checks...
System check identified no issues (0 silenced).
August 20, 2021 - 13:23:22
Django version 3.2.4, using settings 'smartlab.settings'
Starting ASGI/Channels version 3.0.3 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/storages/backends/sftpstorage.py", line 115, in _mkdir
self._mkdir(parent)
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/storages/backends/sftpstorage.py", line 115, in _mkdir
self._mkdir(parent)
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/storages/backends/sftpstorage.py", line 115, in _mkdir
self._mkdir(parent)
[Previous line repeated 2 more times]
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/storages/backends/sftpstorage.py", line 114, in _mkdir
if not self.exists(parent):
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/storages/backends/sftpstorage.py", line 151, in exists
self.sftp.stat(self._remote_path(name))
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/storages/backends/sftpstorage.py", line 87, in sftp
self._connect()
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/storages/backends/sftpstorage.py", line 61, in _connect
self._ssh.load_host_keys(known_host_file)
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/paramiko/client.py", line 127, in load_host_keys
self._host_keys.load(filename)
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/paramiko/hostkeys.py", line 101, in load
e = HostKeyEntry.from_line(line, lineno)
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/paramiko/hostkeys.py", line 364, in from_line
key = ECDSAKey(data=decodebytes(key), validate_point=False)
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/paramiko/ecdsakey.py", line 163, in __init__
key = ec.EllipticCurvePublicKey.from_encoded_point(
File "/home/smartlab/larc-smartlab/venv/lib/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py", line 191, in from_encoded_point
if not isinstance(curve, EllipticCurve):
File "/usr/lib/python3.9/abc.py", line 98, in __instancecheck__
return _abc_instancecheck(cls, instance)
RecursionError: maximum recursion depth exceeded in comparison
Request resulted in error: maximum recursion depth exceeded in comparison
In settings.py, I have the following:
DEFAULT_FILE_STORAGE = 'storages.backends.sftpstorage.SFTPStorage'
SFTP_STORAGE_HOST = '192.168.1.103'
SFTP_STORAGE_ROOT = '/home/smartlab/larc-smartlab/media'
SFTP_STORAGE_PARAMS = {
"username": "[username on remote]",
"password": "[password on remote]"
}
And on my models, I have fields like this:
from storages.backends.sftpstorage import SFTPStorage
...
image = models.ImageField(null=True, storage=SFTPStorage())
I am working with the following versions of these packages:
cryptography=3.4.7
paramiko=2.7.2
django-storages=1.11.1
django=3.2.4
I have looked all over for someone who had the same problem, but nothing seems to be out there. Any ideas on why this recursion is happening in cryptography? How can I set up my SFTP storage to fix this? Thanks!
This error message was in my case misleading, since it's the key file which wasn't correctly read (path was not the good one). It took me some time to figure it out since the error was misleading.
For the records, here are my SFTP settings:
SFTP_STORAGE_HOST = env("SFTP_STORAGE_HOST", default="")
SFTP_STORAGE_ROOT = env("SFTP_STORAGE_ROOT", default="")
SFTP_STORAGE_PORT = env("SFTP_STORAGE_PORT", default="")
SFTP_STORAGE_USER = env("SFTP_STORAGE_USER", default="")
SFTP_KEY_FILENAME = env("SFTP_KEY_FILENAME", default="")
SFTP_STORAGE_PARAMS = {
'port': SFTP_STORAGE_PORT,
'username': SFTP_STORAGE_USER,
'key_filename': SFTP_KEY_FILENAME,
}