I'm trying to use the xml.metadata.insert service on an installation of Geonetwork 3.1. I've had success putting the parameters (a snippet in the case of data) directly in the URL in a web-browser, such as the correct response is returned (uuid and id of the created resource) and a metadata record is created.

However, trying to emulate the same thing in either python (through the "requests" package) or in postman, results in a strange behaviour of a 200 status code, but html being returned (below) instead and the resource not being created.

<!DOCTYPE html
  SYSTEM "html">
<html ng-app="gn_login" lang="eng" id="ng-app">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>ICES Metadata Catalogue - International Council for the Exploration of the Sea (ICES)</title>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="description" content="">
        <meta name="keywords" content="">
        <link rel="icon" sizes="16x16 32x32 48x48" type="image/png" href="../../images/logos/favicon.png">
        <link href="rss.search?sortBy=changeDate" rel="alternate" type="application/rss+xml" title="ICES Metadata Catalogue - International Council for the Exploration of the Sea (ICES)">
        <link href="portal.opensearch" rel="search" type="application/opensearchdescription+xml" title="ICES Metadata Catalogue - International Council for the Exploration of the Sea (ICES)">
        <link href="/geonetwork/static/gn_login_default.css" rel="stylesheet" media="screen">
        <link href="/geonetwork/static/bootstrap-table.min.css" rel="stylesheet" media="screen">
        <link href="/geonetwork/static/ng-skos.css" rel="stylesheet" media="screen">
        <link href="/geonetwork/static/srv_custom_style.css" rel="stylesheet" media="screen">

    <body data-ng-controller="GnCatController">
        <div class="navbar navbar-default gn-top-bar" data-ng-hide="layout.hideTopToolBar" data-ng-include="'../../catalog/templates/top-toolbar.html'"></div>
        <div data-ng-include="'../../catalog/templates/signin.html'"></div>
        <div ng-include="'../../catalog/templates/info.html'"></div>
        <script>var geonet = {provide:function(s){},require:function(s){}};</script>
        <script src="/geonetwork/static/lib.js"></script>
        <script src="/geonetwork/static/gn_login.js"></script>
            <div class="alert" data-ng-hide="">

Is there anything that I'm doing incorrectly to receive this response?


It's been a few years since I was working with GeoNetwork, but I think you may need to handle authentication. With the requests library you can use a Session to store your credentials. Here's a function I used as part of a larger script.

def create_geonetwork_session(self):
    BASE_URL = "https://yourgeonetworksite.com/geonetwork/srv/eng/"
    LOGIN = BASE_URL + "j_spring_security_check"
    self.gn_session = requests.Session()
    self.gn_session.auth = (self.USER, self.PASSWORD)
    login_r = self.gn_session.post(LOGIN)

The most important thing is using requests.Session() and supplying your credentials in a tuple to session.auth. Once you have a session created, use that for performing your insert (ie. instead of requests.post, use session.post) and the login should get passed along.

Hope this helps!

  • 1
    Yes, this was exactly what I was looking for and works perfectly. Thank you! – gremey May 8 '19 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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