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版本的差異,還是其他?
它也可能是平臺特定的。我在redhat上的2.7.5版本上得到了這個錯誤。在ubuntu上,2.7.3和2.7.5都可以正常運行 – Pankaj 2014-09-19 21:52:48