Невозможно подключиться к SFTP из Amazon Managed Apache Airflow, но можно подключиться из локальногоPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Невозможно подключиться к SFTP из Amazon Managed Apache Airflow, но можно подключиться из локального

Сообщение Anonymous »

Я пытаюсь подключиться от Amazon Managed Apache Airflow к SFTP-серверу, но возникает ошибка.

Код: Выделить всё

[2024-10-27, 16:22:12 UTC] {{transport.py:1909}} INFO - Connected (version 2.0, client OpenSSH_6.6.1p1) 

Код: Выделить всё

[2024-10-27, 16:22:12 UTC] {{transport.py:1909}} INFO - Auth banner: b'Ubuntu 14.04.6 LTS\n' 

Код: Выделить всё

[2024-10-27, 16:22:12 UTC] {{transport.py:1909}} INFO - Authentication (publickey) failed.
Однако тот же локальный скрипт Python может подключиться.
Я заметил, что paramiko неоднократно пытается подключиться к SFTP, даже если он терпит неудачу, когда я пытаюсь подключиться локально (журналы вставлены ниже), и в конечном итоге это удается. Однако, похоже, этого не происходит, когда я запускаю тот же код через воздушный поток AWS Managed Apache.
Это скрипт Python, который у меня есть. Раньше я работал с SFTP, но впервые работаю с интеграцией воздушного потока AWS Managed Apache с SFTP.
Буду очень благодарен за любую помощь.

Код: Выделить всё

import os
import paramiko
import logging
import pytz
import re
from io import StringIO
import pandas as pd
logging.basicConfig(level=logging.DEBUG)
from dotenv import load_dotenv

load_dotenv()

pdt_timezone = pytz.timezone('America/Los_Angeles')
# hostname = os.getenv("hostname1")
# username = os.getenv("username1")
# port = int(os.getenv("port1"))
# keyfilepath = os.getenv("keyfilepath1")
# passphrase = os.getenv("passphrase1")

class SFTPtoS3loader:
def __init__(self, hostname, username, port, passphrase=None, password=None, keyfilepath=None):
self.hostname = hostname
self.username = username
self.port = port
self.passphrase = passphrase
self.password = password
self.keyfilepath = '''-----BEGIN OPENSSH PRIVATE KEY-----     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx     -----END OPENSSH PRIVATE KEY-----'''

def connect_to_sftp(self):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
key_file = re.sub(r' {5}', '\n', self.keyfilepath)
key_file = StringIO(key_file)
private_key = paramiko.RSAKey.from_private_key(key_file,
password=self.passphrase)
client.connect(hostname=self.hostname, username=self.username,
port=22,
passphrase=self.passphrase, pkey=private_key,
allow_agent=True,look_for_keys=True,
disabled_algorithms=dict(pubkeys=["rsa-sha2-512", "rsa-sha2-256"]))
sftp = client.open_sftp()
return sftp

def read_file_into_dataframe(self):
sftp = SFTPtoS3loader.connect_to_sftp(self)
file_list = sftp.listdir('from_dmd/aim_feed')
file_to_read = 'from_dmd/aim_feed/' + file_list[0]
with sftp.file(file_to_read, 'r') as remote_file:
file_content = remote_file.read().decode()  # Decode the file content to a string

# Use StringIO to read the file content into a DataFrame
file_buffer = StringIO(file_content)
df = pd.read_csv(file_buffer)
print(df.columns)
return df

if __name__ == '__main__':
# Instantiate the SFTPtoS3loader class with environment variables
loader = SFTPtoS3loader(
hostname=os.getenv('hostname1'),
username=os.getenv('username1'),
port=int(os.getenv('port1')),
passphrase=os.getenv('passphrase1'),
password=os.getenv('password1')
# keyfilepath=os.getenv('keyfilepath')
)

# Call the method to read files from SFTP
df = loader.read_file_into_dataframe()
print(df)

Это журналы успешного локального соединения SFTP.

Код: Выделить всё

DEBUG:paramiko.transport:client lang: 

Код: Выделить всё

DEBUG:paramiko.transport:server lang: 

Код: Выделить всё

DEBUG:paramiko.transport:kex follows: False

Код: Выделить всё

DEBUG:paramiko.transport:=== Key exchange agreements ===

Код: Выделить всё

DEBUG:paramiko.transport:Kex: [email protected]

Код: Выделить всё

DEBUG:paramiko.transport:HostKey: ssh-ed25519

Код: Выделить всё

DEBUG:paramiko.transport:Cipher: aes128-ctr

Код: Выделить всё

DEBUG:paramiko.transport:MAC: hmac-sha2-256

Код: Выделить всё

DEBUG:paramiko.transport:Compression: none

Код: Выделить всё

DEBUG:paramiko.transport:=== End of kex handshake ===

Код: Выделить всё

DEBUG:paramiko.transport:kex engine KexCurve25519 specified hash_algo 

Код: Выделить всё

DEBUG:paramiko.transport:Switch to new keys ...

Код: Выделить всё

DEBUG:paramiko.transport:Adding ssh-ed25519 host key for data.dmdconnects.com: b'1a87b0ce12c36b78bf21a957d53c7ae7'

Код: Выделить всё

DEBUG:paramiko.transport:Trying SSH key b'9dd379b45d4ef4b28b234f3d6ea9d81c'

Код: Выделить всё

DEBUG:paramiko.transport:userauth is OK

Код: Выделить всё

DEBUG:paramiko.transport:Finalizing pubkey algorithm for key of type 'ssh-rsa'

Код: Выделить всё

DEBUG:paramiko.transport:Our pubkey algorithm list: ['ssh-rsa']

Код: Выделить всё

DEBUG:paramiko.transport:Server-side algorithm list:  ['']

Код: Выделить всё

DEBUG:paramiko.transport:Agreed upon 'ssh-rsa' pubkey algorithm

Код: Выделить всё

DEBUG:paramiko.transport:Finalizing pubkey algorithm for key of type 'ssh-rsa'

Код: Выделить всё

DEBUG:paramiko.transport:Our pubkey algorithm list: ['ssh-rsa']

Код: Выделить всё

DEBUG:paramiko.transport:Server-side algorithm list: ['']

Код: Выделить всё

DEBUG:paramiko.transport:Agreed upon 'ssh-rsa' pubkey algorithm

Код: Выделить всё

INFO:paramiko.transport:Auth banner: b'Ubuntu 14.04.6 LTS\n'

Код: Выделить всё

INFO:paramiko.transport:Authentication (publickey) failed.

Код: Выделить всё

DEBUG:paramiko.transport:Trying SSH agent key b'bcd6af1f62fde3407ecd79d38ecf1493'

Код: Выделить всё

DEBUG:paramiko.transport:userauth is OK

Код: Выделить всё

DEBUG:paramiko.transport:Finalizing pubkey algorithm for key of type 'ssh-rsa'

Код: Выделить всё

DEBUG:paramiko.transport:Our pubkey algorithm list: ['ssh-rsa']

Код: Выделить всё

DEBUG:paramiko.transport:Server-side algorithm list: ['']

Код: Выделить всё

DEBUG:paramiko.transport:Agreed upon 'ssh-rsa' pubkey algorithm

Код: Выделить всё

DEBUG:paramiko.transport:Finalizing pubkey algorithm for key of type 'ssh-rsa'

Код: Выделить всё

DEBUG:paramiko.transport:Our pubkey algorithm list: ['ssh-rsa']

Код: Выделить всё

DEBUG:paramiko.transport:Server-side algorithm list: ['']

Код: Выделить всё

DEBUG:paramiko.transport:Agreed upon 'ssh-rsa' pubkey algorithm

Код: Выделить всё

INFO:paramiko.transport:Authentication (publickey) failed.

Код: Выделить всё

DEBUG:paramiko.transport:Trying SSH agent key b'6d0c453545e3225099ca99064119b28a'

Код: Выделить всё

DEBUG:paramiko.transport:userauth is OK

Код: Выделить всё

DEBUG:paramiko.transport:Finalizing pubkey algorithm for key of type 'ssh-rsa'

Код: Выделить всё

DEBUG:paramiko.transport:Our pubkey algorithm list: ['ssh-rsa']

Код: Выделить всё

DEBUG:paramiko.transport:Server-side algorithm list: ['']

Код: Выделить всё

DEBUG:paramiko.transport:Agreed upon 'ssh-rsa' pubkey algorithm

Код: Выделить всё

DEBUG:paramiko.transport:Finalizing pubkey algorithm for key of type 'ssh-rsa'

Код: Выделить всё

DEBUG:paramiko.transport:Our pubkey algorithm list: ['ssh-rsa']

Код: Выделить всё

DEBUG:paramiko.transport:Server-side algorithm list: ['']

Код: Выделить всё

DEBUG:paramiko.transport:Agreed upon 'ssh-rsa' pubkey algorithm

Код: Выделить всё

INFO:paramiko.transport:Authentication (publickey) successful!

Код: Выделить всё

DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes

Код: Выделить всё

DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes

Код: Выделить всё

DEBUG:paramiko.transport:Secsh channel 0 opened.

Код: Выделить всё

DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok

Код: Выделить всё

INFO:paramiko.transport.sftp:[chan 0] Opened sftp connection (server version 3)
PS: При установке возникает та же проблема

Код: Выделить всё

apache-airflow-providers-sftp
и попробуйте подключиться через вкладку «Соединения» в Apache Airflow.

Подробнее здесь: https://stackoverflow.com/questions/791 ... to-connect
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»