我正在尝试以下方法 -
import urllib2
page = urllib2.urlopen('http://dviappvmtca01:9001/deploy/?jobname=\blah12345')
print page.getcode()
我可以在我的浏览器中使用httpfox打开该网站,然后我会看到404.如果我使用上面的脚本尝试使用python,我会得到以下转储 -
Traceback (most recent call last):
File "C:\test.py", line 3, in <module>
page = urllib2.urlopen('http://dviappvmtca01:9001/deploy/?jobname=\blah12345')
File "C:\Python27\lib\urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 410, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 448, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 500: INTERNAL SERVER ERROR
答案 0 :(得分:2)
urllib2.urlopen
返回500,因为引用the standard,“服务器遇到意外情况,导致无法完成请求。”
服务器的日志文件可能会提供有关服务器返回500的原因的信息。