Python ftplib WinError 10060

拈花ヽ惹草 提交于 2020-02-24 05:17:08

问题


I am learning to retrieve files from an ftp server using ftplib from this link : https://docs.python.org/2/library/ftplib.html

When i run this code

from ftplib import FTP
ftp = FTP('ftp.debian.org')
ftp.login()

I get

TimeoutError: [WinError 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

From this answer https://stackoverflow.com/questions/4946960/when-using-ftplib-in-python#= i get to know that this is a server side issue which can be fixed by changing to ACTV mode.

So i changed my code to

from ftplib import FTP
ftp = FTP()
ftp.set_pasv(True)
ftp.connect('ftp.debian.org')
ftp.login()

Still same error. Can anyone tell me what other reasons could there be from my problem?

Edit - Using Python 3.6.1 on Thonny(IDE) in a 64 bit Win 10 environment


回答1:


Nothing wrong with this code. It works for me. Maybe the server was just very slow at the time you tried it. You can set a timeout in the connect:

ftp.connect('ftp.debian.org',timeout=seconds)


来源:https://stackoverflow.com/questions/44106200/python-ftplib-winerror-10060

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!