Old Noob Python 3.6 FTP神秘错误消息

时间:2017-11-27 16:34:51

标签: python

使用Python 3.6 成功从mssqlserver检索数据并查询oracle以获取历史数据并通过Pandas将其导出到制表符分隔文件,然后我希望能够ftp到另一个mssql服务器位置。由于我之前没有尝试过,我试验如下:

\\\\\\\\\\\\\\\\\\\  这有效:传递硬编码变量  \\\\\\\\\\\\\\\\\\\\

from ftplib import FTP

host='myserver'
host_name='group_user_name'
host_pw='hostpassword'
host_dir='myworkingdirectory'

ftp = FTP(host)
ftp.login(user=host_name, passwd =host_pw)
ftp.cwd(host_dir)

filename = 'c:/temp/cigfun.txt'
fn = 'cigfun.txt' 

def placeFile():
    ftp.storbinary('STOR '+fn, open(filename, 'rb'))
    ftp.quit()

placeFile()

\\\\\\\\\\\\\\ 这也有效:硬编码 \\\\\\\\\\\\\\

from ftplib import FTP

ftp = FTP('myserver')
ftp.login(user='group_user_name', passwd ='hostpassword')
ftp.cwd('myworkingdirectory')
ftp.retrlines('LIST')

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

这不连接:从MSSQL中的存储过程中检索数据

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

if sql_id == str(5): 
        sql_cursor.execute("[dbo].[usp_GetProcess_"+seq_action+"] @sql_id = "+ sql_id)
        table = sql_cursor.fetchall()
        for row in table:
            host = "'"+row[1]+"'"
            host_name = "'"+row[2]+"'"
            host_pw = "'"+row[3]+"'"
            host_dir = "'"+row[4]+"'"
            host_dir = re.sub('[cd ]', '', host_dir)
            ftp_file = row[9]
            f_type = row[10]
            if f_type == "Tab (txt)":
                f_type = '.txt'
            elif f_type == "Comma (csv)":
                f_type = '.csv'
            else: f_type = '.xlsx'

            path_file = "'"+ftp_file + f_type+"'"
            fn="'"+os.path.basename(path_file)
            path_file = path_file.replace(r'\\','/')

            from ftplib import FTP
            ftp = FTP(host)
            ftp.login(user = host_name, passwd = host_pw)
            ftp.cwd(host_dir)

\\\\\\\\\\\\\\ 抛出以下错误:

File "C:\Users\A22021\AppData\Local\Continuum\anaconda332\lib\socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
gaierror: [Errno 11004] getaddrinfo failed

除了我在编码上的笨拙努力(只有我使用Python的第三次生产尝试),你能看到任何明显会导致失败的事吗?错误信息是如此神秘。 我怀疑它可能与编码变量赋值有关,但我现在感到困惑。任何建设性的建议都赞赏。 PLG

0 个答案:

没有答案