Python urllib2.urlopen returns a HTTP error 503

DDS Boletus picture DDS Boletus · Dec 8, 2014 · Viewed 7.2k times · Source

Here you can see my code snippet. Since 3 days it does not work any longer. My python is running under Ubuntu 10.04.4 LTS. Python version is 2.6.5.

#!/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)
...

here the returned Error-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

Answer

Joe picture Joe · Dec 8, 2014

The service is not currently working. curl:

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

also returns a 503:

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

The service is using CloudFlare, which provides a form of DDoS protection that requires you to use a full web browser to connect.

Although you could likely work around it, by deciding to use this service, the site operators are declaring that they don't want you to connect using a script.

This is not a programming problem; you'll need to determine why the service is not available to scripts.