0

I am trying to access a CSW (Catalog Service for the Web) using the MetaSearch in QGIS. The CSW Api works fine in PostMan with the API key authentication but I can't set the MetaSearch to use an API key. I have managed to add my key to the authentication in QGIS but have no Idea how to use it in MetaSearch.

here is the metasearch document.

Has anybody done that or should I make a plugin myself or is there maybe another way to connect to a CSW?

Edit: Checking the owslib in my QGIS, it turns out the headers property for CatalogServiceWeb class suggested by @juto96 is removed. I filled a report to see how it happened. The response from the csw is also parsed only as XML while my response is a JSON.

1 Answer 1

1

The MetaSearch plugin uses the CatalogueServiceWeb class from the owslib.csw module to establish the connection to the CSW. CatalogueServiceWeb takes a 'headers' argument, which is not used in MetaSearch plugin. I suppose you could write your own function that creates a CatalogueServiceWeb instance with your api-key in the header argument. That would look something like this:

Cant test it properly, because i dont have a CSW with API Key authentication! Here is an example with a random header key

from owslib.csw import CatalogueServiceWeb

csw = CatalogueServiceWeb(url='https://umweltportal.schleswig-holstein.de/csw?service=CSW&request=GetCapabilities', headers={'Accept-Language':'de,en-US;q=0.7,en;q=0.3'})

print(csw.operations)

If the connection is ok, you can start querying the CSW. For that you can refer to the docs of the owslib.


Resources:
owslib documentation
MetaSearch Plugin Source Code
owslib Source Code

8
  • Creating my own function, you mean I should build a new plugin?
    – msc87
    Commented Oct 17 at 7:08
  • 1
    I would recommend you to write the function first and test it in the QGIS Python console. If it works how you want it, you can put it in a custom plugin. The owslib library, btw, comes preinstalled with QGIS.
    – juto96
    Commented Oct 17 at 7:12
  • For some reason, it throws an error saying TypeError: __init__() got an unexpected keyword argument 'headers'. Looking at owslib, there is a parameter called headers.
    – msc87
    Commented Oct 17 at 9:18
  • I edited my post. It has a working example now with a http header.
    – juto96
    Commented Oct 17 at 9:56
  • I am running your code and same error. I have QGIS 3.34.11-Prizren and run the code in Python editor.
    – msc87
    Commented Oct 17 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.