How to overcome urlopen error [WinError 10060]?

I followed this tutorial, but I still haven't been able to get the output. Below is my code inview.py

def index(request):

 #html="a"
 #url= requests.get("https://www.python.org/")
 #page = urllib.request.urlopen(url)
 #soup = BeautifulSoup(page.read())
 #soup=url.content
 #urllib3.disable_warnings()
 #requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
 #url=url.content
 #default_headers = make_headers(basic_auth='myusername:mypassword')
 #http = ProxyManager("https://myproxy.com:8080/", headers=default_headers)

 r = urllib.request.urlopen('http://www.aflcio.org/Legislation-and-Politics/Legislative-Alerts').read()
 soup = BeautifulSoup(r)
 url= type(soup)

 context={"result":url,}
 return render (request, 'index.html',context)

      

Output:

urlopen error [WinError 10060] The connection attempt failed because the connected side did not respond properly after a while, or the connection could not be established because the connected host was unable to respond

+3


source to share


1 answer


If you are sitting behind a firewall or something similar, you may have to specify a proxy server to pass the request.

Below is an example of using the query library.



import requests

proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}

requests.get('http://example.org', proxies=proxies)

      

0


source







All Articles