2014-09-04 55 views
1

我的机器上有python 2.7.3,当我运行下面的代码时,它运行得很好。addinfourl实例没有属性'getcode' - Python 2.7.5

response = urllib.urlopen(myUrl, params) 
if response.getcode() != 200 and response.getcode() != 204: 
    print "response status:", \ 
    response.getcode(), response.read() 

然而,当我的同事试图运行我的剧本,他得到了以下错误:

AttributeError: addinfourl instance has no attribute 'getcode' 

他有蟒蛇2.7.5。大多数答案建议使用urllib2。但我不想使用它,因为它会导致很多代码更改。这是由于Python版本的差异,还是其他?

回答

0

据我可以告诉它是一个版本问题。它适用于2.7.3版本(Debian),但不适用于2.4(CentOS)。这两种情况都使用urllib2。

我得到了关于“addfourl”的同样的错误。

+0

它也可能是平台特定的。我在redhat上的2.7.5版本上得到了这个错误。在ubuntu上,2.7.3和2.7.5都可以正常运行 – Pankaj 2014-09-19 21:52:48

相关问题