-1
我是一個Python的新手,並嘗試從配置文件params.ini讀取IP和登錄信息。 ini文件的內容是:從配置文件讀取IP地址不工作
[Login]
FtpIP = 1.1.x.x
UID = anonymous
PWD = [email protected]
[Directory]
Upload Directory =/
Home Directory = C:/Users/MyDocuments/Python/FilesUpload/**
我寫的代碼是:
import ftplib
import configparser
config = configparser.ConfigParser()
config.sections()
config.read('params.ini')
ftp = ftplib.FTP()
TargetIP = config.get('Login','FtpIP')
print (TargetIP)
ftp.connect(TargetIP)
我得到這個錯誤:
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond*
如果我直接輸入IP到代碼,那麼它的作品。請幫忙。
是否'打印(TargetIP)'打印正確的價值? – dpk2442
是的,它的確如此。但是當我嘗試建立連接時,它失敗了。 –
根據錯誤消息,看起來好像主機沒有響應。你確定在你嘗試之前沒有任何改變的FTP主機? – dpk2442