Ошибка 10060 python

OS: Windows 7; Python 2.7.3 using the Python GUI Shell

I’m trying to read a website through Python, and several authors use the urllib and urllib2 libraries. To store the site in a variable, I’ve seen a similar approach proposed:

import urllib
import urllib2
g = "http://www.google.com/"
read = urllib2.urlopen(g)

The last line generates an error after a 120+ seconds:

> Traceback (most recent call last):   File "<pyshell#27>", line 1, in
> <module>
>     r = urllib2.urlopen(o)   File "C:Python27liburllib2.py", line 126, in urlopen
>     return _opener.open(url, data, timeout)   File "C:Python27liburllib2.py", line 400, in open
>     response = self._open(req, data)   File "C:Python27liburllib2.py", line 418, in _open
>     '_open', req)   File "C:Python27liburllib2.py", line 378, in _call_chain
>     result = func(*args)   File "C:Python27liburllib2.py", line 1207, in http_open
>     return self.do_open(httplib.HTTPConnection, req)   File "C:Python27liburllib2.py", line 1177, in do_open
>     raise URLError(err) URLError: <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>

I tried bypassing the g variable and trying to urlopen("http://www.google.com/") with no success either (it generates the same error after the same length of time).

def check_web_server(host, port, path):
        h = httplib.HTTPConnection(host, port)
        h.request('GET',path)
        resp = h.getresponse()
        print 'HTTP Response:'
        print '   status =', resp.status
        print '   reason =', resp.reason
        print 'HTTP Headers:'
        for hdr in resp.getheaders():
                print '  %s: %s' % hdr

I called this function like this check_web_server('www.python.org',80,'/')
but it gave me this error
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

You can see the code clearly here
http://pastebin.com/V9KpGkvw

I have searched here in Stackoverflow but I didnt find any relevant questions
sorry I am new to site ,if I Did anything wrong.

C:UserspankaAppDataLocalProgramsPythonPython35-32python.exe C:/Users/panka/PycharmProjects/bucky/webCrawling.py
Traceback (most recent call last):
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesurllib3connection.py», line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesurllib3utilconnection.py», line 83, in create_connection
raise err
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesurllib3utilconnection.py», line 73, in create_connection
sock.connect(sa)
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

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesurllib3connectionpool.py», line 601, in urlopen
chunked=chunked)
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesurllib3connectionpool.py», line 346, in _make_request
self._validate_conn(conn)
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesurllib3connectionpool.py», line 850, in _validate_conn
conn.connect()
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesurllib3connection.py», line 284, in connect
conn = self._new_conn()
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesurllib3connection.py», line 150, in _new_conn
self, «Failed to establish a new connection: %s» % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x03C85FB0>: Failed to establish a new connection: [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

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesrequestsadapters.py», line 440, in send
timeout=timeout
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesurllib3connectionpool.py», line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesurllib3utilretry.py», line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’buckysroom.org’, port=443): Max retries exceeded with url: /trade/search.php?page=1 (Caused by NewConnectionError(‘<urllib3.connection.VerifiedHTTPSConnection object at 0x03C85FB0>: Failed to establish a new connection: [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’,))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File «C:/Users/panka/PycharmProjects/bucky/webCrawling.py», line 39, in
trade_spider(1)
File «C:/Users/panka/PycharmProjects/bucky/webCrawling.py», line 9, in trade_spider
source_code = requests.get(url)
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesrequestsapi.py», line 72, in get
return request(‘get’, url, params=params, **kwargs)
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesrequestsapi.py», line 58, in request
return session.request(method=method, url=url, **kwargs)
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesrequestssessions.py», line 508, in request
resp = self.send(prep, **send_kwargs)
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesrequestssessions.py», line 618, in send
r = adapter.send(request, **kwargs)
File «C:UserspankaAppDataLocalProgramsPythonPython35-32libsite-packagesrequestsadapters.py», line 508, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host=’buckysroom.org’, port=443): Max retries exceeded with url: /trade/search.php?page=1 (Caused by NewConnectionError(‘<urllib3.connection.VerifiedHTTPSConnection object at 0x03C85FB0>: Failed to establish a new connection: [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’,))

Process finished with exit code 1

Здравствуйте, имею небольшой скрипт на Py, по отправке сообщения через SMPT сервер Яндекса:

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

import smtplib

def send_email(recipient, subject, msg):
    sender = 'mail@yandex.ru'
    password = 'mailpass'    
    
    server = smtplib.SMTP('smpt.yandex.ru', 587)
    server.starttls()

    try:
        server.login(sender, password)
        msg = MIMEText(msg)
        msg['Subject'] = subject
        server.sendmail(sender, recipient, msg.as_string())
        return 'Message send'
    except Exception as exception:
        return f'Check ur credentailsn{exception}'
    
def main():
    recipient = input('Enter recipient')
    subject = input('Enter subject')
    msg = input('Enter msg')

    print(send_email(recipient, subject, msg))

if __name__ == '__main__':
    main()

При попытке отправки письма содержания «123» возникает следующая ошибка:

Traceback (most recent call last):
  File "c:UsersUserDesktopprojmain.py", line 30, in <module>
    main()
  File "c:UsersUserDesktopprojmain.py", line 27, in main
    print(send_email(recipient, subject, msg))
  File "c:UsersUserDesktopprojmain.py", line 10, in send_email   
    server = smtplib.SMTP('smpt.yandex.ru', 587)
  File "C:UsersUserAppDataLocalProgramsPythonPython310libsmtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
  File "C:UsersUserAppDataLocalProgramsPythonPython310libsmtplib.py", line 341, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "C:UsersUserAppDataLocalProgramsPythonPython310libsmtplib.py", line 312, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "C:UsersUserAppDataLocalProgramsPythonPython310libsocket.py", line 845, in create_connection
    raise err
  File "C:UsersUserAppDataLocalProgramsPythonPython310libsocket.py", line 833, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] Попытка установить соединение была безуспешной, т.к. от другого компьютера за требуемое время не получен нужный отклик, или было разорвано уже установленное соединение из-за неверного отклика уже подключенного компьютера

В какую сторону копать?
Пробовал запускать этот код с двух разных машин.

When we are crawling some sites using python, we get WinError 10060 error. In this tutorial, we will introduce this error and disucss how to fix it.

If you are using python 3 to crawl sites, you may get this error.

understand winerror 10060 for beginners

The reason is: 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

How to fix WinError 10060?

There are some methods to fix this error.

1. Increase connect time

If your network is not good, it will take a long time to connect a host, in that case, you should increase the connect time of your application.

Best Practice to Set Timeout for Python urllib.request.urlretrieve() – Python Web Crawler Tutorial

2. Improve your network

If the speed of your network is not good, it is hard to connect servers. In that case, you should improve your network.

3. Make sure your compter run few applications

If your computer are running many applications, these applications will decrease the performance of processing network. In that situation, you can close some applications or restart your computer.

4. Check the performance of destination server

If the performace of destination server is not good, you connet it, it will take a long time to response to you, then WinError 10060 will occur. As to this situation, we can not do anything.

Понравилась статья? Поделить с друзьями:
  • Ошибка 10060 download master
  • Ошибка 1006 это
  • Ошибка 1006 фанук
  • Ошибка 1006 ситроен
  • Ошибка 1006 на телефоне