2014-12-08 2 views
2

여기에서 제 코드를 볼 수 있습니다. 3 일이 지난 후에는 더 이상 작동하지 않습니다. 내 Python은 Ubuntu 10.04.4 LTS에서 실행 중입니다. Python 버전은 2.6.5입니다. 여기Python urllib2.urlopen이 HTTP 오류 503을 반환합니다.

#!/usr/bin/env python 
import urllib2 as ur 
... 
webpage = [] 

site = "http://www.gametracker.com/server_info/94.250.218.247:25200/top_players/" 
hdr = {'User-Agent': 'Mozilla/5.0'} 
req = ur.Request(site , headers=hdr) 
data = ur.urlopen(req) 
for line in data: 
    line = line.split(",") 
    webpage.append(line) 
... 

반환 된 오류-MSG

Traceback (most recent call last): 

File "read_top5.py", line 21, in <module> 
    data = ur.urlopen(req) 
File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen 
    return _opener.open(url, data, timeout) 
File "/usr/lib/python2.6/urllib2.py", line 397, in open 
    response = meth(req, response) 
File "/usr/lib/python2.6/urllib2.py", line 510, in http_response 
    'http', request, response, code, msg, hdrs) 
File "/usr/lib/python2.6/urllib2.py", line 435, in error 
    return self._call_chain(*args) 
File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain 
    result = func(*args) 
File "/usr/lib/python2.6/urllib2.py", line 518, in http_error_default 
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) 
urllib2.HTTPError: HTTP Error 503: Service Temporarily Unavailable 
+4

이 질문은 프로그래밍보다는 서비스의 이용 가능 여부에 관한 주제이므로 다루지 않습니다. – Joe

+1

그건 그렇고, ['requests'] (http://docs.python-requests.org/en/latest/)를 사용하십시오. Waaaaaay 웹 요청을 실행하기위한 더 나은 API. – jpmc26

답변

5

이 서비스는 현재 작동하지 않습니다. curl : 서비스가 연결하는 전체 웹 브라우저를 사용하여 당신을 필요로하는 form of DDoS protection을 제공 CloudFlare을 사용

HTTP/1.1 503 Service Temporarily Unavailable 
Date: Mon, 08 Dec 2014 09:37:17 GMT 
Content-Type: text/html; charset=UTF-8 
Server: cloudflare-nginx 

:

curl -i "http://www.gametracker.com/server_info/94.250.218.247:25200/top_players/" 

는 503을 반환합니다.

이 서비스를 사용하기로 결정하면 사이트 운영자가 스크립트를 사용하여 연결하지 않기를 선언합니다.

프로그래밍상의 문제는 아닙니다. 스크립트에서 서비스를 사용할 수없는 이유를 알아야합니다.

+0

브라우저를 사용하여 사이트를 방문하면 현재 작동하고 있습니다. –

+0

CloudFlare ... 이제 의미가 있습니다 ... 감사합니다 ... 나 혼자서보아야 할 것입니다, 수치 스럽습니다 ... –

1

이것은 사이트의 기능입니다. 그것은 일종의 반 DDoS 시스템의 일부인 것처럼 보입니다. 그것이 503을 반환하는 이유는 혼란 스럽지만 사이트 자체는 분명합니다.

은 내가 curl 명령 Joe 위가했는데, 이것은 내가 다시 얻을 응답입니다 : 몸이 내용을 포함

HTTP/1.1 503 Service Temporarily Unavailable 
Date: Mon, 08 Dec 2014 09:47:41 GMT 
Content-Type: text/html; charset=UTF-8 
Transfer-Encoding: chunked 
Connection: keep-alive 
Set-Cookie: __cfduid=d32f001037fafc1363bf86d29be0baf921418032061; expires=Tue, 08-Dec-15 09:47:41 GMT; path=/; domain=.gametracker.com; HttpOnly 
X-Frame-Options: SAMEORIGIN 
Cache-Control: no-cache 
Server: cloudflare-nginx 
CF-RAY: 19580b02d7c70f21-IAD 

<!DOCTYPE HTML> 
<html lang="en-US"> 
<head> 
    <meta charset="UTF-8" /> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" /> 
    <meta name="robots" content="noindex, nofollow" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title>Just a moment...</title> 
    <style type="text/css"> 
    html, body {width: 100%; height: 100%; margin: 0; padding: 0;} 
    body {background-color: #ffffff; font-family: Helvetica, Arial, sans-serif; font-size: 100%;} 
    h1 {font-size: 1.5em; color: #404040; text-align: center;} 
    p {font-size: 1em; color: #404040; text-align: center; margin: 10px 0 0 0;} 
    #spinner {margin: 0 auto 30px auto; display: block;} 
    .attribution {margin-top: 20px;} 
    </style> 

    <script type="text/javascript"> 
    //<![CDATA[ 
    (function(){ 
    var a = function() {try{return !!window.addEventListener} catch(e) {return !1} }, 
    b = function(b, c) {a() ? document.addEventListener("DOMContentLoaded", b, c) : document.attachEvent("onreadystatechange", b)}; 
    b(function(){ 
     var a = document.getElementById('cf-content');a.style.display = 'block'; 
     setTimeout(function(){ 
     var t,r,a,f, sdDUenl={"xRvHG":+((!+[]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![]+!![]+!![]))}; 
     t = document.createElement('div'); 
     t.innerHTML="<a href='/'>x</a>"; 
     t = t.firstChild.href;r = t.match(/https?:\/\//)[0]; 
     t = t.substr(r.length); t = t.substr(0,t.length-1); 
     a = document.getElementById('jschl-answer'); 
     f = document.getElementById('challenge-form'); 
     ;sdDUenl.xRvHG*=+((!+[]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]));sdDUenl.xRvHG-=+((!+[]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]));sdDUenl.xRvHG+=+((!+[]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]));sdDUenl.xRvHG*=+((!+[]+!![]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![]));sdDUenl.xRvHG-=+((!+[]+!![]+!![]+!![]+!![]+[])+(+[]));sdDUenl.xRvHG-=+((!+[]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]));sdDUenl.xRvHG*=+((!+[]+!![]+[])+(!+[]+!![]+!![]+!![]));sdDUenl.xRvHG-=+((!+[]+!![]+!![]+!![]+[])+(!+[]+!![]+!![]));sdDUenl.xRvHG*=+((+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![]+!![]));sdDUenl.xRvHG+=+((!+[]+!![]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![]+!![]+!![]));a.value = parseInt(sdDUenl.xRvHG, 10) + t.length; 
     f.submit(); 
     }, 5850); 
    }, false); 
    })(); 
    //]]> 
</script> 


</head> 
<body> 
    <table width="100%" height="100%" cellpadding="20"> 
    <tr> 
     <td align="center" valign="middle"> 
      <div class="cf-browser-verification cf-im-under-attack"> 
    <noscript><h1 data-translate="turn_on_js" style="color:#bd2426;">Please turn JavaScript on and reload the page.</h1></noscript> 
    <div id="cf-content" style="display:none"> 
    <img id="spinner" src="/cdn-cgi/images/spinner-2013.gif" /> 
    <h1><span data-translate="checking_browser">Checking your browser before accessing</span> gametracker.com.</h1> 
    <p data-translate="process_is_automatic">This process is automatic. Your browser will redirect to your requested content shortly.</p> 
    <p data-translate="allow_5_secs">Please allow up to 5 seconds&hellip;</p> 
    </div> 
    <form id="challenge-form" action="/cdn-cgi/l/chk_jschl" method="get"> 
    <input type="hidden" name="jschl_vc" value="3cecd7cab5d69708a3b1081e462824d0"/> 
    <input type="hidden" id="jschl-answer" name="jschl_answer"/> 
    </form> 
</div> 


      <div class="attribution"><a href="http://www.cloudflare.com/" target="_blank" style="font-size: 12px;">DDoS protection by CloudFlare</a></div> 
     </td> 
    </tr> 
    </table> 
</body> 
</html> 

주, 503 상태 코드 임에도 불구하고. 이것은 브라우저에서 페이지를 방문 할 때 실제로 본 것과 일치합니다. 먼저 위의 응답에서 볼 수있는 "anti-DDoS"페이지로 전송 된 다음 URL에서 요청 된 페이지 (JavaScript를 통해 명백하게)로 리디렉션되었습니다. 이것은 브라우저 외부에서 예상대로 작동하지 않는 이유를 설명합니다. 파이썬 웹 요청은 자바 스크립트를 실행하여 리디렉션을 수행하지 않습니다.

확실히 서비스입니다. 당신은 그것을 만든 사람들과상의해야합니다 왜 그들이 어떻게 당신이 그것을 기대하고 있는지 알아보십시오. Accept 헤더를 설정하면 API 호출에 대해 다른 끝점이 있는지 여부를 확인하거나 끝점이 다르게 응답 할 수 있습니다. (application/json은 JSON을 다시 나타낼 때 사용할 수 있습니다.)

관련 문제