本文介绍了URLError: <urlopen error [Errno 11004] getaddrinfo failed>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上正在编写代码来检查链接是直接链接还是错误链接或重定向或文件下载链接

I am actually writing a code to check whether the links are direct or error or redirect or file download link

当我写这些行时

import urllib2
response = urllib2.urlopen('http://google.com')

我收到如下错误:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    response = urllib2.urlopen('http://google.com')
  File "C:\Python27\lib\urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "C:\Python27\lib\urllib2.py", line 391, in open
    response = self._open(req, data)
  File "C:\Python27\lib\urllib2.py", line 409, in _open
    '_open', req)
  File "C:\Python27\lib\urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 1173, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "C:\Python27\lib\urllib2.py", line 1148, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno 11004] getaddrinfo failed>

您是否有任何想法出现此错误?这是因为我的公司不允许以这种方式访问​​网站吗?谢谢

Y is this error occuring any ideas?? Is this because my company doenst allow to access websites this way?Thanks

推荐答案

有点晚了,但是您是否检查了 http://google.com 在您的浏览器中?你得到什么回应?

A bit late, but did you check http://google.com in your browser? What response do you get?

截至目前,HTTP 连接被转发到 HTTPS,这对我有用:导入 urllib2response = urllib2.urlopen('http://google.com')打印 response.read()

As of now, HTTP connections are forwarded to the HTTPS and this works for me:import urllib2response = urllib2.urlopen('http://google.com')print response.read()

    <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's informati
on, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for
." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta
 content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script>(function(){
window.google={kEI:'WjgxV8I8jLCPA5iGn4gK',kEXPI:'1350654,3700257,3700388,4029815,4031109,4032677,4036509,4036527,4038012,4039268,4
042553,4042792,4043492,4045841,4048347,4049557,4051558,4052304,4056038,4057170,4057739,4057836,4058299,4058337,4059767,4061155,406
1181,4061552,4062222,4062287,4062299,4062333,4062407,4062632,4062706,4062971,4062987,4063095,4063111,4063126,4063829,4063879,40639
29,4064307,4064318,4064449,4064496,4064501,4064815,4064931,4065592,4065787,4065796,4065855,4065945,4066098,4066101,4066615,4066662
,4066706,4067087,4067307,8300096,8300273,8503585,8504026,8504107,8504280,8504282,8504308,8504456,8504522,10200083,10201847',authus
er:0,kscs:'c9c918f0_24'};google.kHL='en';})();(function(){google.lc=[];google.li=0;google.getEI=function(a){for(var b;a&&(!a.getAt
tribute||!(b=a.getAttribute("eid")));)a=a.parentNode;return b||google.kEI};google.getLEI=function(a){for(var b=null;a&&(!a.getAttr
ibute||!(b=a.getAttribute("leid")));)a=a.parentNode;return b};google.https=function(){return"https:"==window.location.protocol};go
ogle.ml=function(){return null};google.wl=function(a,b){try{google.ml(Error(a),!1,b)}catch(c){}};google.time=function(){return(new
 Date).getTime()};google.log=function(a,b,c,e,g){a=google.logUrl(a,b,c,e,g);if(""!=a){b=new Image;var d=google.lc,f=google.li;d[f]

这篇关于URLError: &lt;urlopen error [Errno 11004] getaddrinfo failed&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 13:52