[MapProxy] Can mapproxy-seed be made to ignore 500 errors?

José M López-Cepero cepe at gmbm.net
Mon Oct 13 06:44:41 PDT 2014


Hi all

For the benefit of anybody who encounters the same problem, I solved it by
creating a simple PHP script to act as a mostly transparent relay but
returning a blank image for any failure.

Here's a bit of code:


<?php

$g = $_SERVER['REQUEST_URI'];

$p = explode('?',$g,2);
if (count($p) == 1) $p[] = '';

$url = 'http://my.wms.server/WMS-service.cgi?' . $p[1];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$r=curl_exec($ch);
$i = curl_getinfo($ch);
curl_close($ch);

$code = $i['http_code'];
$ct = $i['content_type'];

$hasimg = false;

$is500 = ($code == 500);
$isException = ($ct == 'application/vnd.ogc.se_xml' && strpos($r,'<!DOCTYPE
ServiceExceptionReport') !== FALSE);
if ($is500 || $isException
&& isset($_GET['width'])
&& isset($_GET['height'])) {

$a = imagecreate($_GET['width'],$_GET['height']);
imagecolorallocate($a, 100, 0, $isException ? 100 : 0);
 $code = 200;
$ct = 'image/png';
$hasimg = true;

}

http_response_code($code);
header('Content-Type: ' . $ct);

if ($hasimg) imagepng($a);
else die($r);


You'll have to tweak it a bit, at the very minimum setting the URL to the
correct URL of the service. Then place it somewhere where it can be
accessed (in a local webserver would be ideal) and point MapProxy to the
PHP file.

This uses cURL to pass the request to the desired server but detects two
possible failure outcomes - a 500 code (Internal Server Error) and an
exception report (once I got rid of the 500 errors, these started popping
up and halting the seeding). If any of these situations is detected and
width&height are passed in the request, it returns an empty PNG image - red
for 500, purple for exceptions. (If you aren't requesting PNGs, modify the
code accordingly).

It's kind of an ugly hack, but it has allowed me to complete seeding, which
was the entire point :) It also prevents MapProxy from requesting the
damaged tiles from the WMS service time an again, which is desirable if the
errors can be assumed to be permanent.


2014-09-23 16:55 GMT+02:00 Oliver Tonnhofer <olt at omniscale.de>:

> Hi,
>
> On 23.09.2014, at 14:12, José M López-Cepero wrote:
> > What I would need (other than the server to behave itself, of course) is
> a way to make mapproxy-seed skip those 500 errors, but continue with the
> next tiles instead of dying. As far as I have been able to tell, there is
> no configuration option I can change for that, and while I guess that it
> should be a easy hack I don't know nearly enough Python to know where to
> look. I'm using MapProxy 1.7.1, installed as described in the Installation
> section of the docs (ie. in an independent virtual environment).
>
> Sorry, there is no option to enable that.
>
> Regards,
> Oliver
>
> --
> Oliver Tonnhofer  | Omniscale GmbH & Co KG  | http://omniscale.com
> OpenStreetMap WMS and tile services         | http://maps.omniscale.com
>
>
>


-- 
J. M. López-Cepero
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapproxy/attachments/20141013/c39c9a44/attachment.html>


More information about the MapProxy mailing list