2013-03-19 7 views
1

나는 내가 503 오류가 다음 얻을 실행에 갈 때 이제(503) 오류가 파이썬을 사용하여 Google 특허에 액세스하려고 할 때

import urllib2 

url = 'http://www.google.com/search?tbo=p&q=ininventor:"John-Mudd"&hl=en&tbm=pts&source=lnt&tbs=ptso:us' 
req = urllib2.Request(url, headers={'User-Agent' : "foobar"}) 

response = urllib2.urlopen(req) 

아래의 코드를 사용하여 Google 특허 데이터를 당길 수 있었다 오늘 아침 일찍. 나는이 코드를 30 회 반복했을 뿐이었다. (나는 30 명으로 구성된 모든 특허를 얻으 려하고있다.) 어두운 추측에

HTTPError         Traceback (most recent call last) 
<ipython-input-4-01f83e2c218f> in <module>() 
----> 1 response = urllib2.urlopen(req) 

C:\Python27\lib\urllib2.pyc in urlopen(url, data, timeout) 
    124  if _opener is None: 
    125   _opener = build_opener() 
--> 126  return _opener.open(url, data, timeout) 
    127 
    128 def install_opener(opener): 

C:\Python27\lib\urllib2.pyc in open(self, fullurl, data, timeout) 
    404   for processor in self.process_response.get(protocol, []): 
    405    meth = getattr(processor, meth_name) 
--> 406    response = meth(req, response) 
    407 
    408   return response 

C:\Python27\lib\urllib2.pyc in http_response(self, request, response) 
    517   if not (200 <= code < 300): 
    518    response = self.parent.error(
--> 519     'http', request, response, code, msg, hdrs) 
    520 
    521   return response 

C:\Python27\lib\urllib2.pyc in error(self, proto, *args) 
    436    http_err = 0 
    437   args = (dict, proto, meth_name) + args 
--> 438   result = self._call_chain(*args) 
    439   if result: 
    440    return result 

C:\Python27\lib\urllib2.pyc in _call_chain(self, chain, kind, meth_name, *args) 
    376    func = getattr(handler, meth_name) 
    377 
--> 378    result = func(*args) 
    379    if result is not None: 
    380     return result 

C:\Python27\lib\urllib2.pyc in http_error_302(self, req, fp, code, msg, headers) 
    623   fp.close() 
    624 
--> 625   return self.parent.open(new, timeout=req.timeout) 
    626 
    627  http_error_301 = http_error_303 = http_error_307 = http_error_302 

C:\Python27\lib\urllib2.pyc in open(self, fullurl, data, timeout) 
    404   for processor in self.process_response.get(protocol, []): 
    405    meth = getattr(processor, meth_name) 
--> 406    response = meth(req, response) 
    407 
    408   return response 

C:\Python27\lib\urllib2.pyc in http_response(self, request, response) 
    517   if not (200 <= code < 300): 
    518    response = self.parent.error(
--> 519     'http', request, response, code, msg, hdrs) 
    520 
    521   return response 

C:\Python27\lib\urllib2.pyc in error(self, proto, *args) 
    442   if http_err: 
    443    args = (dict, 'default', 'http_error_default') + orig_args 
--> 444    return self._call_chain(*args) 
    445 
    446 # XXX probably also want an abstract factory that knows when it makes 

C:\Python27\lib\urllib2.pyc in _call_chain(self, chain, kind, meth_name, *args) 
    376    func = getattr(handler, meth_name) 
    377 
--> 378    result = func(*args) 
    379    if result is not None: 
    380     return result 

C:\Python27\lib\urllib2.pyc in http_error_default(self, req, fp, code, msg, hdrs) 
    525 class HTTPDefaultErrorHandler(BaseHandler): 
    526  def http_error_default(self, req, fp, code, msg, hdrs): 
--> 527   raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) 
    528 
    529 class HTTPRedirectHandler(BaseHandler): 

HTTPError: HTTP Error 503: Service Unavailable 
+1

이 503 인 것입니다 : "503 :.. \t 서비스를 사용할 수 없음 서버는 현재 사용할 수 없습니다 일반적으로,이 임시 상태 (이 유지 보수를 위해 아래로 과부하 또는 때문에)" – iamnotmaynard

+0

@iamnotmaynard ...하지만 브라우저에서 URL을 방문 할 수 있습니다 ... http : //www.google.com/search? tbo = p & q = ininventor : "John-Mudd"& hl = ko & tbm = pts & source = lnt & tbs = ptso : us – Chris

+0

@Chris, 그것은 IP 및/또는 사용자 에이전트 당 ratelimit 일 수 있습니다. 그럼에도 불구하고이 오류를 처리해야합니다 (다시 시도 하시겠습니까?). –

답변

1

샷 :

당신이 응답에서 "다시 시도-후 헤더는"거기 있는지 살펴 않았다. 응답 헤더 필드는 503 (서비스 를 사용할 수 없음) 응답과 함께 사용할 수있는 후 재시도-방법을 나타 내기 위해

14.37

재시도-후 : 그것은 503

From RFC 2616와 실제 가능성입니다 서비스가 이 될 것으로 기대되면 요청한 클라이언트가 사용할 수 없게됩니다. 이 필드는 과 함께 3xx (리디렉션) 응답을 사용하여 사용자 에이전트에게 리디렉션 된 요청을 보내기 전에 대기하는 최소 시간을 나타낼 수도 있습니다. 이 필드의 값은 HTTP-date 또는 응답 시간 후 초 (십진수)의 정수일 수 있습니다. = "다시 시도-후" " 재시도-후"(HTTP-날짜 | 델타 초)

의 사용의 두 가지 예는 재시도-후 : 1999년 12월 31일 (금) 그리니치 표준시 23시 59분 59초 재시도 후속 : 120

후자의 예에서 지연은 2 분입니다.