How to solve the [error 11004] getaddrinfo failed error in nltk downloader

Recently, I used nltk as a downloader in my homework related to automatic Q & A. I used another computer to solve the problem, but I didn’t record the solution. I immediately forgot and spent about 2 hours looking for a solution. Therefore, I want to record the solution now.

import nltk

nltk.download('stopwords')
nltk.download('reuters')
nltk.download('punkt')

When executing the above code, an error is found error loading stopwords: & lt; Urlopen error [errno 11004] getaddrinfo failed , the following methods are available through practical operation.

Find the hosts file under C: \ windows \ system32 \ drivers \ etc , open it as an administrator, and add the following line of IP address to the end of hosts.

185.199.108.133 raw.githubusercontent.com

As shown in the figure below,
after adding and running again, you will find that the download is successful

The address of raw.github is changed frequently, resulting in unsuccessful download

It is possible that the address may be changed frequently, resulting in unsuccessful downloading. We can open the website for querying the IP address: https://www.ipaddress.com/ Enter raw. Githubusercontent. Com to find the corresponding new IP address.

give an example

We have added the IP address to the hosts and found that it was still unsuccessful. Therefore, let’s see if the download failed due to the change of the IP address of raw.github. We open https://websites.ipaddress.com/ website, enter raw.githubusercontent.com , and click look up
. It is found that four IPS have been found. We replace the content in hosts with

185.199.109.133 raw.githubusercontent.com

Then we re execute and find success.

If the above solutions are not solved, you can leave a message and we can communicate together~

The above solutions are from the solution reference link. Thank you very much!!

Read More: