Python socket.error: [Errno 10054] The remote host forced the shutdown of an existing connection.

Source: Internet
Author: User
Tags connection reset
Because of a lot of use of a Web site Urlopen operation, so it will be identified as an attack by the site. Downloads are sometimes no longer allowed. led to Urlopen (), Request.read () had been stuck there. Errno10054 will be thrown at the end.

This error is connection reset Bypeer. The legendary remote host has reset this connection. The reason may be that the socket timeout is too long, or it may be after the request =urllib.request.urlopen (URL), there is no request.close () operation, or there may be no sleep for a few seconds, causing the site to assume that this behavior is an attack.

Specific solutions such as the following code:

Import socket
Import time
Timeout = 20
Socket.setdefaulttimeout (timeout) #这里对整个socket层设置超时时间. If you use the socket again in subsequent files, you do not have to set
Sleep_download_time = 10
Time.sleep (sleep_download_time) #这里时间自己设定
Request = Urllib.request.urlopen (URL) #这里是要读取内容的url
Content = Request.read () #读取, it is common to report anomalies here
Request.close () #记得要关闭

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.