Hello Andreas,
another recommendation would be to use the python library owslib <https://geopython.github.io/OWSLib/index.html> by Tom Kralidis that offers various interactions with ogc-compliant APIs including CSW. It has nice wrapper tools in owslib.utils that might support you in what you are trying to do. At least it is handling the authentication, cookie or XR…F(?) token exchange etc. and also uses the requests class for the connection.
But another thing - I wasn't aware you could add attachments to metadata entries. Is the attachment you want to download really 'physically bound' to geonetwork file structure, or added via a reference? If so, you could first extract its link from the metadata entry and then download from the linked resource.
Cheers,
Lars
Am 10.11.20 um 16:45 schrieb Andreas Böhme:
Hi guys,
I am currently trying to access my Geonetwork via python. I want to write a short script that dwonloads an attachment from a geonetwork entry of which I know the UUID. Sounds not too cmplicated but I can not manage the Login to the site.
Here is the code I use:
from requestsimport Sessionwith Session()as s:
token ="***" login_data = {"username":"***","password":"***","csrf_token": token}
#print(login_data) s.post("https://***/geonetwork/srv/ger/catalog.signin", login_data)
r = s.get("https://***/geonetwork/srv/api/records/UUID/attachments/***.zip") #print(r.status_code) #print(r.headers['content-type']) #print(r.encoding) I always get a 403 error message and do not have any clue why it is not working. I am no experienced programmer so any help would be really appreciated. Many thx and all the best Andreas
_______________________________________________
GeoNetwork-users mailing list
GeoNetwork-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-users
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork
--
Dr. Lars Möller
HCDC Metadatenadministration
Helmholtz-Zentrum Geesthacht
Zentrum für Material und Küstenforschung
-Modellierung zur Bewertung von Küstensystemen (KBS)
Max-Planck-Straße 1
21502 Geesthacht
Germany
Fon +49 (0) 4152- 87 - 1849
Fax +49 (0) 4152- 87 - 41849
E-mail: lars.moeller@anonymised.com
www.hzg.de
Helmholtz-Zentrum Geesthacht Zentrum für Material- und Küstenforschung GmbH Max-Planck-Straße 1 I 21502 Geesthacht I Deutschland/Germany
Geschäftsführung/Board of Management: Prof. Dr. Matthias Rehahn, Silke Simon Vorsitzender des Aufsichtsrates/Chairman of the Supervisory Board: Ministerialdirigent Engelbert Beyer Amtsgericht Lübeck HRB 285 GE (Register Court) Internet: http://www.hzg.de