无法在Apache Airflow中使用FTPHook连接到FTP服务器

问题描述 投票:0回答:1

我正在尝试在Apache Airflow中使用FTPHook类。以下是以ftp.gnu.org为例的测试代码:

from airflow.contrib.hooks.ftp_hook import FTPHook
hook = FTPHook('gnu')
print(hook.list_directory(''))

此代码返回错误:

{base_hook.py:84} INFO - Using connection to: id: gnu. Host: ftp.gnu.org, Port: None, Schema: None, Login: None, Password: None, extra: {}
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    print(hook.list_directory(''))
  File "/home/ubuntu/.anaconda3/envs/airflow/lib/python3.7/site-packages/airflow/contrib/hooks/ftp_hook.py", line 127, in list_directory
    conn.cwd(path)
  File "/home/ubuntu/.anaconda3/envs/airflow/lib/python3.7/ftplib.py", line 631, in cwd
    return self.voidcmd(cmd)
  File "/home/ubuntu/.anaconda3/envs/airflow/lib/python3.7/ftplib.py", line 278, in voidcmd
    return self.voidresp()
  File "/home/ubuntu/.anaconda3/envs/airflow/lib/python3.7/ftplib.py", line 251, in voidresp
    resp = self.getresp()
  File "/home/ubuntu/.anaconda3/envs/airflow/lib/python3.7/ftplib.py", line 246, in getresp
    raise error_perm(resp)
ftplib.error_perm: 530 Please login with USER and PASS.

但是,如果将这行代码hook.get_conn().login()放在print函数之前,则一切正常。这是错误还是我做错了?

ftp airflow airflow-operator
1个回答
0
投票
username ='anonymous'和

password ='anonymous @'。如docs的第一个示例所示,这似乎是ftplib的默认设置,但是如果您将其保留为空,则Airflow会将这些值更改为None

© www.soinside.com 2019 - 2024. All rights reserved.