Hey everyone,
I’m hitting a wall with an SFTP issue and could use some guidance. I’m working on automating a data transfer from Snowflake to an external partner via SFTP. The setup is running Python in a Docker container, designed to integrate with Airflow for daily automation. I’m using environment variables to securely manage sensitive info like SFTP credentials.
I’ve managed to replicate my production environment exactly in a local dev Docker container, running the same image, settings, and ect I keep getting this error:
ERROR - An unexpected error occurred during encryption: [Errno 6] No such device or address
Current Setup & Environment Variables
I’m loading critical info (like the SFTP host, port, username, and password) from environment variables. Here’s a quick look at how I’m doing that:
import os
import paramiko
SFTP_HOST = os.getenv(‘SFTP_HOST’)
SFTP_PORT = int(os.getenv(‘SFTP_PORT’, ‘22’))
SFTP_USERNAME = os.getenv(‘SFTP_USERNAME’)
SFTP_PASSWORD = os.getenv(‘SFTP_PASSWORD’)
Connecting to SFTP with Paramiko
I’m using Paramiko to handle the SFTP connection. Here’s the core setup for connecting and uploading:
try:
transport = paramiko.Transport((SFTP_HOST, SFTP_PORT))
transport.connect(username=SFTP_USERNAME, password=SFTP_PASSWORD)
sftp = paramiko.SFTPClient.from_transport(transport)
# File transfer logic
sftp.put(local_file_path, remote_file_path)
except paramiko.SFTPError as e:
print(f"SFTP Error: {e}")
finally:
sftp.close()
transport.close()
Docker & Airflow Environment
I’m running this script in Docker, which is orchestrated by Airflow in production. Here’s a snippet from the Dockerfile, showing how I’m loading the environment variables:
Dockerfile example
ENV SFTP_HOST=sftp.example.com
ENV SFTP_USERNAME=my_username
ENV SFTP_PASSWORD=my_password
Despite having an identical setup in both dev and production environments, the error only occurs in production. The specific error [Errno 6] No such device or address suggests an address or device issue, but since the credentials and connection details are the same, I’m at a loss for what could be different between the environments.
Has anyone encountered this kind of error with Paramiko or Docker, especially in Airflow-managed environments? Any insights or troubleshooting tips would be greatly appreciated!