我是Python的新手,试图从配置文件params.ini中读取IP和登录信息。 ini文件的内容是:
[Login]
FtpIP = 1.1.x.x
UID = anonymous
PWD = r@ee.com
[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,那么它可以工作。请帮忙。
答案 0 :(得分:0)
你能试试吗
try:
ftp = ftplib.FTP(config.get('Login','FtpIP'))
ftp.login(config.get('Login','UID'), config.get('Login','PWD'))
except ftplib.all_errors, e:
print str(e)