[python] python3.x encountered 'cannot connect because the target computer actively refused' problem solution using urllib

Problem Description

Today, when I used a program written before to crawl the POI of the Gaode map, I found that it suddenly failed to run successfully. The problems were as follows:

[WinError 10061] 由于目标计算机积极拒绝,无法连接。

solution process

1. At the beginning, I thought it was something wrong with the program, so I rewrote the simplest program verification:

# !/usr/bin/env python
# -*- coding:utf-8 -*-
import urllib.request

url = 'http://www.baidu.com'
data = urllib.request.urlopen(url).read()
data = data.decode('UTF-8')
print(data)

The result conforms to the rules of program bug debugging - it doesn't work

2. So, I went to the Internet to see how the great gods solved it. Sure enough, there are still a lot of people who have this problem. I believe everyone has tried the solution provided by most people, that is to modify the proxy in "Internet Options". The general steps are to open "Internet Options" in the browser - "LAN Settings" Check "Automatically detect settings", as shown below


Figure 1 LAN settings

I modified it according to the above method and it still doesn't work. . .

3. I went to find the problem again, and found that a friend on the Internet said that the network connection was unstable . At this time, I remembered that the network I used to run the program before did not seem to be the one currently used, so I changed the WIFI connection. Unexpectedly, the program actually moved, haha! It also conforms to the bug debugging rules - just don't know why.


summary of a problem

In the end, the problem is solved, but after all, it is still unclear why the problem occurred, and it is not clear which step above played a role, or played a role together, so we can only write a plan for your reference. I hope someone can find the root cause and solve the problem completely.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325565949&siteId=291194637