나는 테스트하고있는 간단한 웹 사이트가 있습니다. 로컬 호스트에서 실행 중이며 웹 브라우저에서 액세스 할 수 있습니다. 색인 페이지는 단순히 "실행 중"이라는 단어입니다. urllib.urlopen
은 페이지를 성공적으로 읽지 만 urllib2.urlopen
은 읽지 않습니다.urllib.urlopen하지만 작동하지 않습니다 urllib2.urlopen
Traceback (most recent call last):
File "urltest.py", line 5, in <module>
print urllib2.urlopen("http://127.0.0.1").read()
File "C:\Python25\lib\urllib2.py", line 121, in urlopen
return _opener.open(url, data)
File "C:\Python25\lib\urllib2.py", line 380, in open
response = meth(req, response)
File "C:\Python25\lib\urllib2.py", line 491, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python25\lib\urllib2.py", line 412, in error
result = self._call_chain(*args)
File "C:\Python25\lib\urllib2.py", line 353, in _call_chain
result = func(*args)
File "C:\Python25\lib\urllib2.py", line 575, in http_error_302
return self.parent.open(new)
File "C:\Python25\lib\urllib2.py", line 380, in open
response = meth(req, response)
File "C:\Python25\lib\urllib2.py", line 491, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python25\lib\urllib2.py", line 418, in error
return self._call_chain(*args)
File "C:\Python25\lib\urllib2.py", line 353, in _call_chain
result = func(*args)
File "C:\Python25\lib\urllib2.py", line 499, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 504: Gateway Timeout
어떤 아이디어 :
import urllib, urllib2
print urllib.urlopen("http://127.0.0.1").read() # prints "running"
print urllib2.urlopen("http://127.0.0.1").read() # throws an exception
여기에 스택 추적이있다 : 여기에 문제가 (이 실제 스크립트가 아닌 다른 테스트 스크립트의 단순화)을 보여줍니다 스크립트입니까? 내가 urllib2
의 고급 기능 중 일부를 필요로하게 될 수도 있으므로 urllib
을 사용하여 더 이상이 문제를 이해하고 싶지는 않습니다.
스크립트가 3 줄 밖에 없었고 프록시에 대해 아무 것도 나타내지 않는 환경 변수가 없기 때문에이 방법으로 프록시를 사용하는 방법이나 이유를 알 수는 없지만 문제가 해결되었습니다. 그래도 해결 된 것이 좋으므로 도움을 주셔서 감사합니다. –
OpenerDirector 인스턴스에 'urlopen'속성이 없습니다. 위의 프래그먼트를 opener.open (...으로 변경해야합니다. – ryan