Errno 10060 and IMAP4_SSL - python

I'm trying to write a script that logs into my email server(yahoo) and checks for messages from a certain sender. This is my first time useing the IMAP module and I can't seem to get it to work. Right now I have only a few lines of code.
from imaplib import *
server = IMAP4_SSL('mail.yahoo.com')
server.login('myusername','mypassword')
mail_folders = server.list()
for folders in mail_folders:
print(folders)
at this point all I'm trying to do is login to the mail server and retrieve a list of folders. However I never get connected. the interpreter throws a
[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
I'm not sure if this has something to do with SSL or what. I have managed to get a connection with httplib.HTTPSConnection, But I would rather use IMAP then webscrape.

I think the problem is just the server name that is wrong. Replacing 'mail.yahoo.com' with 'imap.mail.yahoo.com' worked for me.

Related

Python ftplib WinError 10060

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
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)
I had the same problem. As the ftplib description Passive mode is on by default. So set it to False. It works for me.
ftp.set_pasv(False)
Or active passive in server(it's Debian 11 for me) as define the min & max port:
pasv_min_port=10000
pasv_max_port=11000
Of course, you need add the ports in firewall:
ufw allow 10000:11000/tcp
Setting passive mode to False works for me. Thanks!!
ftp.set_pasv(False)

Python 3.4 - failing to connect to http with urllib

I'm trying to run a simple Python script which connects to a website and reads a document on the website, but it fails. Any help, would be most welcome, thank you!
The code is as follows:
import urllib.request
fhand = urllib.request.urlopen('http://www.py4inf.com/code/romeo.txt')
for line in fhand:
print (line.strip())
And I'm getting the following two error messages:
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
urllib.error.URLError: {urlopen error [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}
This is the windows error, not urllib's one. The latter has a handy default timeout value of never, but the former depends on settings of your proxy (with default being 60 seconds for initial connection and 120 for any further GET requests.
I can't help much with windows, but at least now you know where to look.
I had this same issue, and tried specifying a timeout in the urllib.request.urlopen, but no dice.
What did work was including a header, as described here. The first answer worked, and so did the second, so I used the simpler, second solution.

What Is The Cause Of This URLOpen Error

My Python code downloads a file from our website. The code fails to download the file on certain clients computers. I cant for the life of me figure out why the file fails to download when the script runs on certain computers but works on others.
The error that occurs on certain computers is:
<urlopen 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>
The clients confirm they are connected to the internet and they can successfully download the same file(same url) through a web browser. Its incredibly weird that the script works on some computers and not on others, that they are connected to the internet but cannot download the file and that they can download the file through a browser but not through my script? Maybe the cause it that they are not an admin user?
What can cause this kind of error?
My simple code:
try:
source_buffer = urllib2.urlopen(URL)
source_code = source_buffer.read()
source_buffer.close()
return source_code
except Exception, e:
print e
PS: Do you think this is a proxy error? If it is can you explain what exactly is going wrong? Proxies have always confused me - well I understand when using a proxy all http, https, ftp requests go through a proxy computer (intermediary) before going out to the internet but I dont understand how this error can be caused from a proxy? Whats going wrong? Whats occurring?
It could be proxy, or looking at the error message, it could also be that local/personal firewall settings are blocking the outgoing requests from your application, or responses from the server from reaching your application. Local firewall settings could easily vary between computers, and this might account for the problem.

Python urlopen IOError: [Errno socket error] [Errno 10060]

I'm looking to get more information about IOError: [Errno socket error] [Errno 10060] when using urlopen in Python 2.7. I am using my personal 35MB/s Internet connection (no proxy).
I've been opening multiple webpages from various websites using a Python script and randomly get this error message from time to time:
webpage = urlopen('http://www.thewebpage.com')
IOError: [Errno 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
This error appeared after trying to open pages from different websites. Therefore, it doesn't seem to be related exclusively to the opening of pages from one particular website. I also got this error using mechanize.
My questions are :
Is this error related to the fact that I am sending multiple requests to the same server within a short amount of time? Would a time-out reduces the chance of getting this error?
Is there any way to prevent it? Could I use a conditional statement to prevent the script from crashing?
My script takes around an hour to run and having to rerun it due to this error is fairly unpleasant.
Sending multiple requests to the same server in short succession could very well cause the server not to respond, since your requests might look like a ddos attack. You can catch the exception with a try-except clause, and try again.

python socket Errno 10060

I'm using python socket to connect to a server but sometimes I get this:
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
when I call the socket.connect method
s= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((self._ipv4address, host_port))
try:
s.connect((dest_ip, dest_port))
except:
raise
Why am I seeing this error? And how do I solve the problem?
You don't need to bind the socket (unless the remote server has an expectation of incoming socket) - it is extremely rare that this would actually be a requirement to connect.
Instead of using sockets to open a website, use urllib2 or mechanize if you need to twiddle forms. They manage cookies, sessions, page state, etc.. Much easier.
Also, if you fail to to connect.. don't give up! Try again, some sites can be pokey to respond. Some may not respond for a while depending - handle it better. Instead of just raising the error, wrap your connection method with an exponential backoff decorator.

Categories

Resources