2012-08-11 3 views
1

안녕하세요 저는 Python 스크립트를 사용하여 웹 상거래 사이트에서 기능을 테스트하고 있습니다.Python 스크립트 이상한 문제

Logged in with test_cart 
    Open http://[***]/electronics/page/1 
Search ... iphone 
[****************] 
    File "/home/.../cart-pickup.py", line 58, in alo 
    site = opener.open(url) 
    File "/usr/local/lib/python2.7/urllib2.py", line 400, in open 
    response = self._open(req, data) 
    File "/usr/local/lib/python2.7/urllib2.py", line 418, in _open 
    '_open', req) 
    File "/usr/local/lib/python2.7/urllib2.py", line 378, in _call_chain 
    result = func(*args) 
    File "/usr/local/lib/python2.7/urllib2.py", line 1207, in http_open 
    return self.do_open(httplib.HTTPConnection, req) 
    File "/usr/local/lib/python2.7/urllib2.py", line 1180, in do_open 
    r = h.getresponse(buffering=True) 
    File "/usr/local/lib/python2.7/httplib.py", line 1030, in getresponse 
    response.begin() 
    File "/usr/local/lib/python2.7/httplib.py", line 407, in begin 
    version, status, reason = self._read_status() 
    File "/usr/local/lib/python2.7/httplib.py", line 371, in _read_status 
    raise BadStatusLine(line) 
    httplib.BadStatusLine: '' 
    >>>   

어떤 아이디어 무엇입니다 수 있습니다 나는이 오류를 얻을 때 때때로,이 같은 문제없이 연속 7 일처럼 작동하지만 일이있다, pythonanywhere 사이트에서이 스크립트를 넣어? 사전에 감사

+3

내가 그 파이썬 스크립트에 문제가 생각하지 않지만,에 오히려 문제 대화하려는 웹 서버. –

답변

3

당신은 어떻게 try..except를 사용하여 충돌없이이 상황에서 복구하는 프로그램을 가르 칠 수 :

try: 
    site = opener.open(url) # line 58 in cart-pickup.py 
except IOError: 
    print "Error: Site not loading or it isnt UP. Retrying..." 
    # return site # This will cause a NameError if site is not defined. 
    return url # Perhaps you meant this? 
except httplib.BadStatusLine: 
    # log opening `url` did not succeed, or 
    # queue it to be tried again, etc. 
    pass 
+0

저는 파이썬에서 좀 새로운 것 같습니다. 그래서 나는 잠시 동안 2 개의 예외를 가질 수 있는지를 모른다. 데프 ALO (URL) : 내 코드는 다음과 같습니다 testurl = 1 동안 testurl == 1 : 시도 : 사이트 = opener.open (URL) lagsafe = 0 IO 오류를 제외하고 : 인쇄 "오류 : 사이트가 아닙니다 로드 중입니다. 다시 시도 ... " 돌아 가기 사이트 어떻게 코드를 작성할 수 있습니까? –

+1

현재 예외 다음을 제외하고 두 번째를 추가하십시오. –

+0

이 작동하지 않습니다. 그것은 잘못된 구문을 말하고 두 번째 때를 제외하고 IDLE blinker (나는 윈도우를 사용한다)를 넣는다. –