[Mapserver-users] WMS server - client communication error

Sean Gillies sgillies at frii.com
Mon May 10 09:38:54 EDT 2004


Alexandros, see my comments at the *bottom* ...

On 10/mag/04, at 03:17, Alexandros Chimarios wrote:

>
> Sean and Daniel,
>
> 	First of all thanx for your answers.
>
> I tried the prepareImage() method but it didnt work. After that tried 
> with a
> dummy metada block and all the params in the CONNECTION url but it 
> didnt work
> either.
>
> I am thinking of creating a method in Python until you release the next
> version of MapScript to temporarily give some kinda of solution to 
> Python
> Mapscript programmers. This method which will  download the image in 
> the disk
> using HTTP and then load it in memory creating a new image 
> object(imageObj).
> Then I will be able to combine this raster image with other layers 
> using the
> MapScript layerObj.draw() method.
>
> What do you think about that ?
>
> On Friday 07 May 2004 20:45, Sean Gillies wrote:
>> On 07/mag/04, at 10:40, Howard Butler wrote:
>>> At 11:08 AM 5/7/2004, Sean Gillies wrote:
>>>> On 07/mag/04, at 08:47, Daniel Morissette wrote:
>>>>> Alexandros Chimarios wrote:
>>>>>> Traceback (most recent call last):
>>>>>>   File "./src/test.py", line 131, in ?
>>>>>>     image = mo.draw();
>>>>>>   File "/usr/lib/python2.2/site-packages/mapscript.py", line 1783,
>>>>>> in draw
>>>>>>     def draw(*args): return apply(_mapscript.mapObj_draw,args)
>>>>>> _mapscript.MapServerError: msLookupHashTable: Hash table error.
>>>>>> Invalid hash table or key
>>>>>
>>>>> A similar problem was reported a few weeks ago:
>>>>>
>>>>> http://lists.gis.umn.edu/pipermail/mapserver-dev/2004-April/
>>>>> 000955.html
>>>>>
>>>>> In this case it was with python as well, and it was not possible to
>>>>> reproduce with the regular CGI. Perhaps there is something specific
>>>>> to that flavour of MapScript?  I would suggest that you file a bug
>>>>> about this.
>>>>>
>>>>> Daniel
>>>>
>>>> Alexandros,
>>>>
>>>> The Python mapscript module is set up so that the MapServer error
>>>> stack is
>>>> checked after method calls (such as mapObj.draw), MapServer errors 
>>>> are
>>>> converted to Python exceptions and are raised.
>>>>
>>>> Somewhere in msDrawMap, maybe in the WMS HTTP request code,
>>>> msLookupHashTable
>>>> is being used to access layer or map metadata and is not finding
>>>> something
>>>> it expects.  Maybe your mapfile lacks a WMS metadata parameter?
>>>> In the CGI MapServer, such an error will be reported but will
>>>> not necessarily stop execution of the program.  With the Python
>>>> MapScript,
>>>> unhandled exceptions will stop execution.
>>>>
>>>> I suggest that you try some code like this for now:
>>>>
>>>>     image = mo.prepareImage() # so that it is defined outside the
>>>> try/except
>>>>     try:
>>>>         image = mo.draw()
>>>>     except MapServerError:
>>>>         pass
>>>>
>>>> Let me know how it goes and together we can work towards a better
>>>> solution.
>>>>
>>>> cheers,
>>>> Sean
>>>
>>> Sean,
>>>
>>> prepareImage doesn't cure it.  For me, it was only happening on WMS
>>> images that needed to be projected using GDAL.  I have an Albers map
>>> that I am pulling in a UTM 15 image where it is causing a problem for
>>> me.
>>>
>>> I suspect an error is being put on the stack that is silenced by the
>>> WMS code.  Most things don't pick up on it, but Python is very
>>> sensitive to not silencing exceptions ;)
>>>
>>> I also know that a WMS parameter is not missing because the image is
>>> successfully download (I can send debug info along if requested).
>>>
>>> Howard
>>
>> Howard, it isn't that prepareImage cures anything, I'm just using it 
>> so
>> that
>> image is defined outside the try/except blocks and can be used after
>> we've
>> dodged the hash lookup error.
>>
>> I looked into msDrawWMSLayerLow(), which is called in your case and
>> Alexandros'.
>> A few lines in, we try to look up "wms_sld_body" and "wms_sld_url" in
>> the
>> layer metadata ... if you don't have these defined in your layer,
>> msLookupHashTable() is going to throw an error that stops the Python
>> interpreter.
>> I wouldn't be surprised if there are more such cases, and as the 
>> number
>> of
>> WMS features grow, there will be ever more.
>>
>> IMO, msLookupHashTable() should throw errors like this so that, in
>> Python,
>> layer.getMetaData("foo") raises an exception just like adict["foo"]
>> raises
>> a KeyError if "foo" is not present in the dictionary.  Looks like we
>> have to add
>> some code to msDrawWMSLayerLow to delete these particular errors 
>> before
>> they
>> can hit the Python interpreter.
>>
>> Sean
>>
>>

First, Alexandros, when you reply to this thread where all of us are
posting at the bottom, you *must* follow suit -- it makes it so much
more readable!

I think that your work-around is good, I have been doing the same
thing.  If you are using the 4.2beta MapScript there is a shortcut:
you can pass Python file-like objects to the imageObj constructor
like this

    urlh = 
urllib.urlopen("http://wms?REQUEST=GetMap&FORMAT=image/jpg...")
    img = mapscript.imageObj(0, 0, "GD/JPEG", urlh)

cheers,
Sean

--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies




More information about the mapserver-users mailing list