2017-05-05 98 views
0

我需要創建一個簡單的代碼,將一個.csv文件上傳到FTP服務器。代碼如下。Python ftplib:socket.gaierror:[Errno -3]名稱解析中的臨時失敗

import ftplib 
import os 
import sys 
sourceFilePath = '/home/user/dir/' 
filename = 'testing.csv' 
destinationDirectory = 'anotherDirectory' 
server = 'ftp://12.123.12.234' 
username = 'aUser' 
password = 'passwd1234' 
myFTP = ftplib.FTP(server, username, password) 
myFTP.cwd('/anotherDirectory/') 
myFTP.storbinary('STOR '+filename, open(filename,'rb')) 
myFTP.quit() 

然而,當我運行代碼,我得到以下錯誤:

Traceback (most recent call last): 
    File "./UploadToFTP.py", line 20, in <module> 
    File "./UploadToFTP.py", line 13, in uploadFileFTP 
    myFTP = ftplib.FTP(server, username, password) 
    File "/usr/lib64/python2.6/ftplib.py", line 119, in __init__ 
    self.connect(host) 
    File "/usr/lib64/python2.6/ftplib.py", line 134, in connect 
    self.sock = socket.create_connection((self.host, self.port), 
self.timeout) 
    File "/usr/lib64/python2.6/socket.py", line 553, in create_connection 
    for res in getaddrinfo(host, port, 0, SOCK_STREAM): 
socket.gaierror: [Errno -3] Temporary failure in name resolution 

有沒有人見過這個?這對我來說似乎相當通用,並沒有告訴我很多。就我見過的其他代碼執行相同的任務而言,我目前沒有任何可見的錯誤。任何幫助,將不勝感激。

+0

有沒有* 「未決定錯誤」 *任何地方你的消息。 –

+0

這是我無法確定的。 ;) –

回答

0

構造函數ftplib.FTP的參數host是主機名/ IP地址,而不是URL。

因此,這是錯誤的:

server = 'ftp://12.123.12.234' 

它應該是:

server = '12.123.12.234' 
+0

啊。我應該知道這一點。非常感謝你的時間。 –

相關問題