-1

我是 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,那么它就可以工作。请帮忙。

4

1 回答 1

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)
于 2012-08-28T06:28:42.240 回答