2014-09-03 66 views
0

我想下面 -爲什麼urllib2會返回500?

import urllib2 

page = urllib2.urlopen('http://dviappvmtca01:9001/deploy/?jobname=\blah12345') 
print page.getcode() 

我可以在瀏覽器中打開該網站,並是HttpFox和我/看404。如果我從劇本蟒蛇嘗試了上述我得到以下轉儲 -

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 
+1

信息'\ B'很可能被當作「退格」元字符,而不是「反斜槓和B」。試試'\\ b'? – 2014-09-03 19:53:09

+0

你能提供服務器的日誌文件和/或錯誤日誌文件的相關片段嗎? – 2014-09-03 19:54:42

+0

字符串的問題...哦,我真的希望有一個類似的差異之間的「和」在Python中的Perl中。 – HuStmpHrrr 2014-09-03 19:59:54

回答

2

urllib2.urlopen返回500,因爲,引用the standard服務器遇到阻止其完成請求意外情況」。

服務器的日誌文件可能會提供有關爲什麼服務器返回500

+0

糾正。我有urllib2.open返回作爲404現在。問題是在我的API 。 – whoisearth 2014-09-03 20:06:21

相關問題