[OWSLib-users] error in CSW insert transaction : Document is XML, but not CSW-ish

Chiarello Ernest Ernest.Chiarello at univ-fcomte.fr
Tue May 3 08:34:27 PDT 2016


it works now !! :-)

Le 03/05/2016 17:22, Chiarello Ernest a écrit :
> Thanks Tom
>
> Le 03/05/2016 14:30, Tom Kralidis a écrit :
>>
>> Hi Ernest:
>>
>> On Tue, 3 May 2016, Chiarello Ernest wrote:
>>
>>> Date: Tue, 3 May 2016 11:37:47 +0200
>>> From: Chiarello Ernest <Ernest.Chiarello at univ-fcomte.fr>
>>> To: Tom Kralidis <tomkralidis at gmail.com>, OWSLib-users at lists.osgeo.org
>>> Subject: Re: [OWSLib-users] error in CSW insert transaction : 
>>> Document is XML,
>>>     but not CSW-ish
>>>
>>> Le 03/05/2016 11:11, Chiarello Ernest a écrit :
>>>> new idea !
>>>>
>>>> Le 03/05/2016 11:05, Chiarello Ernest a écrit :
>>>>> Hi Tom,
>>>>>
>>>>> Le 03/05/2016 05:04, Tom Kralidis a écrit :
>>>>>> On Mon, May 2, 2016 at 6:12 AM, Chiarello Ernest
>>>>>> <Ernest.Chiarello at univ-fcomte.fr>  wrote:
>>>>>>> Hi all,
>>>>>>>
>>>>>>> I am trying to insert a metadata in GeoNetwork, according OWSlib
>>>>>>> documentation but it fails with this error message :
>>>>>>> RuntimeError: Document is XML, but not CSW-ish
>>>>>>>
>>>>>>> But above all, i think quotes are missing in the csw 
>>>>>>> transaction. you should
>>>>>>> write :
>>>>>>>
>>>>>>>>>> csw.transaction(ttype='insert', typename='gmd:MD_Metadata',
>>>>>>>>>> record=open("file.xml").read())
>>>>>>> instead of :
>>>>>>>>>> csw.transaction(ttype='insert', typename='gmd:MD_Metadata',
>>>>>>>>>> record=open(file.xml).read())
>>>>>>> Next i recovered a file from another GeoNetwork, in order to be 
>>>>>>> sure that
>>>>>>> the metadata file would be correct.
>>>>>>>
>>>>>>> wget
>>>>>>> https://georchestra-mshe.univ-fcomte.fr/geonetwork/srv/fre/xml.metadata.get?id=17804 
>>>>>>>
>>>>>>> -O metadata.xml
>>>>>>>
>>>>>>> And then i tried to insert this metadata in my GeoNetwork Dev 
>>>>>>> machine :
>>>>>>>
>>>>>>>>>> geonetwork =
>>>>>>>>>> 'http://geonetwork-mshe.univ-fcomte.fr:8080/geonetwork/srv/fre/csw' 
>>>>>>>>>>
>>>>>>>>>> from owslib.csw import CatalogueServiceWeb
>>>>>>>>>> csw = CatalogueServiceWeb(geonetwork)
>>>>>>>>>> csw.transaction(ttype='insert', typename='gmd:MD_Metadata',
>>>>>>>>>> record=open("metadata.xml").read())
>>>>>>> Traceback (most recent call last):
>>>>>>>    File "<stdin>", line 1, in <module>
>>>>>>>    File "/usr/lib/python2.7/dist-packages/owslib/csw.py", line 
>>>>>>> 446, in
>>>>>>> transaction
>>>>>>>      self._invoke()
>>>>>>>    File "/usr/lib/python2.7/dist-packages/owslib/csw.py", line 
>>>>>>> 680, in
>>>>>>> _invoke
>>>>>>>      raise RuntimeError('Document is XML, but not CSW-ish')
>>>>>>> RuntimeError: Document is XML, but not CSW-ish
>>>>>>>
>>>>>>> Can anybody explain to me why my metadata.xml file is not CSW-ish ?
>>>>>>>
>>>>>> My guess is that some sort of authentication is required to make 
>>>>>> CSW-T
>>>>>> requests against the CSW in question.  Try adding the username an
>>>>>> password parameters to the constructor?
>>>>>>
>>>>>> ..Tom
>>>>> sorry, but i do not know how to set username and passord in the 
>>>>> csw transaction.
>>>>>
>>>>> def transaction(self, ttype=None, typename='csw:Record', 
>>>>> record=None, propertyname=None, propertyvalue=None, bbox=None, 
>>>>> keywords=[], cql=None, identifier=None):
>>>>>
>>>>> """
>>>>>
>>>>> Construct and process a Transaction request
>>>>>
>>>>> Parameters
>>>>> ----------
>>>>>
>>>>> - ttype: the type of transaction 'insert, 'update', 'delete'
>>>>> - typename: the typename to describe (default is 'csw:Record')
>>>>> - record: the XML record to insert
>>>>> - propertyname: the RecordProperty/PropertyName to Filter against
>>>>> - propertyvalue: the RecordProperty Value to Filter against (for 
>>>>> updates)
>>>>> - bbox: the bounding box of the spatial query in the form 
>>>>> [minx,miny,maxx,maxy]
>>>>> - keywords: list of keywords
>>>>> - cql: common query language text. Note this overrides bbox, 
>>>>> qtype, keywords
>>>>> - identifier: record identifier. Note this overrides bbox, qtype, 
>>>>> keywords, cql
>>>>>
>>>>>
>>>>>
>>>>> thanks for your help,
>>>>>
>>>>>
>>>>> Ernest.
>>>>>
>>>>
>>>> I realized that username and password should be send when opening 
>>>> CSW !
>>>> csw = CatalogueServiceWeb(geonetwork, skip_caps=True, 
>>>> username='admin', password='admin')
>>>>
>>>> but i have a new error...
>>>>
>>>> >>> geonetwork = 
>>>> 'http://geonetwork-mshe.univ-fcomte.fr:8080/geonetwork/srv/fre/csw'
>>>> >>> from owslib.csw import CatalogueServiceWeb
>>>> >>> csw = CatalogueServiceWeb(geonetwork, skip_caps=True, 
>>>> username='admin', password='admin')
>>>> >>> csw.transaction(ttype='insert', typename='gmd:MD_Metadata', 
>>>> record=open('metadata.xml').read())
>>>> Traceback (most recent call last):
>>>>   File "<stdin>", line 1, in <module>
>>>>   File "/usr/lib/python2.7/dist-packages/owslib/csw.py", line 429, 
>>>> in transaction
>>>>     node1.append(etree.fromstring(record))
>>>>   File "src/lxml/lxml.etree.pyx", line 3213, in 
>>>> lxml.etree.fromstring (src/lxml/lxml.etree.c:82934)
>>>>   File "src/lxml/parser.pxi", line 1819, in 
>>>> lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:124533)
>>>>   File "src/lxml/parser.pxi", line 1707, in lxml.etree._parseDoc 
>>>> (src/lxml/lxml.etree.c:123074)
>>>>   File "src/lxml/parser.pxi", line 1079, in 
>>>> lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:117114)
>>>>   File "src/lxml/parser.pxi", line 573, in 
>>>> lxml.etree._ParserContext._handleParseResultDoc 
>>>> (src/lxml/lxml.etree.c:110510)
>>>>   File "src/lxml/parser.pxi", line 683, in 
>>>> lxml.etree._handleParseResult (src/lxml/lxml.etree.c:112276)
>>>>   File "src/lxml/parser.pxi", line 624, in 
>>>> lxml.etree._raiseParseError (src/lxml/lxml.etree.c:111367)
>>>> lxml.etree.XMLSyntaxError: None
>>>>
>>>> any help ?
>>>>
>>>> Ernest.
>>>
>>> sorry, the metadata file was empty, for an unknow reason... >:o
>>> so, i can try another time, with user authentication :
>>>
>>>>>> geonetwork = 
>>> 'http://geonetwork-mshe.univ-fcomte.fr:8080/geonetwork/srv/fre/csw'
>>>>>> from owslib.csw import CatalogueServiceWeb
>>>>>> csw = CatalogueServiceWeb(geonetwork, skip_caps=True, 
>>>>>> username='admin', 
>>> password='admin')
>>>>>>
>>>>>> csw.transaction(ttype='insert', typename='gmd:MD_Metadata', 
>>> record=open('metadata.xml').read())
>>> Traceback (most recent call last):
>>>  File "<stdin>", line 1, in <module>
>>>  File "/usr/lib/python2.7/dist-packages/owslib/csw.py", line 446, in 
>>> transaction
>>>    self._invoke()
>>>  File "/usr/lib/python2.7/dist-packages/owslib/csw.py", line 680, in 
>>> _invoke
>>>    raise RuntimeError('Document is XML, but not CSW-ish')
>>> RuntimeError: Document is XML, but not CSW-ish
>>>
>>> it seems the error is the same...
>>
>> Are you able to access csw.response after the error?  If not, add a 
>> print
>> statment (self.response) in 
>> https://github.com/geopython/OWSLib/blob/master/owslib/csw.py#L666
>> to see the actual result from the CSW?
>>
> here is the csw.response :
>
> >>> csw.transaction(ttype='insert', typename='gmd:MD_Metadata', 
> record=open('metadata.xml').read())
> <?xml version="1.0" encoding="UTF-8"?>
> <response>
>   <info>Not a CSW Discovery operation: Transaction. Did you mean to 
> use the CSW Publication service? Use service name /csw-publication</info>
> </response>
>
> i hope it will help you.
>
>
i changed the URL, using csw-publication instead of csw, as suggested by 
Kevin Dyke,
in the geonetwork-users list :

 >>> geonetwork = 
'http://geonetwork-mshe.univ-fcomte.fr:8080/geonetwork/srv/fre/csw-publication'
 >>>
 >>> from owslib.csw import CatalogueServiceWeb
 >>> csw = CatalogueServiceWeb(geonetwork, skip_caps=True, 
username='admin', password='admin')
 >>>
 >>> # Transaction: insert
... csw.transaction(ttype='insert', typename='gmd:MD_Metadata', 
record=open('metadata.xml').read())
<?xml version="1.0" encoding="UTF-8"?>
<csw:TransactionResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2">
   <csw:TransactionSummary>
     <csw:totalInserted>1</csw:totalInserted>
     <csw:totalUpdated>0</csw:totalUpdated>
     <csw:totalDeleted>0</csw:totalDeleted>
   </csw:TransactionSummary>
   <csw:InsertResult handleRef="handleRefValue">
     <csw:BriefRecord>
<identifier>7253afc776baa4ed602def02e4ef04d15ef5ebd3</identifier>
     </csw:BriefRecord>
   </csw:InsertResult>
</csw:TransactionResponse>

thanks to both. :-)

Ernest.

>>
>>> what am i missing ?
>>>
>>>
>>> Ernest.
>>>
>>>
>
>


-- 
Ernest CHIARELLO  -  Ernest.Chiarello at univ-fcomte.fr
UMR6049 ThéMA - Théoriser et Modéliser pour Aménager
CNRS / université de Bourgogne Franche-Comté
32 rue Mégevand 25030 BESANÇON Cedex

Tel : 03 81 66 54 80           Mob : 07 82 99 11 08




More information about the OWSLib-users mailing list