Access Geonetwork via Python-Skript

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Access Geonetwork via Python-Skript

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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-users
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork

smime.p7s (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Access Geonetwork via Python-Skript

Rein van t Veer
Hi Andreas,

In my recent post (at
https://sourceforge.net/p/geonetwork/mailman/message/37147884/) I hope you
will find the answer.
It's in the 'update' method, which is part of the MetadataRecord class I
created for convenience.

You can instantiate the class as follows:

my_record = MetadataRecord()

And then you have the update method at your disposal:

my_record.update()

In your case, you'll have to fiddle with this method to return the
attachment instead of updating some metadata fields, though.

Kind regards, good luck,
Rein

Op di 10 nov. 2020 om 16:51 schreef Andreas Böhme <[hidden email]>:

> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/geonetwork-users
> GeoNetwork OpenSource is maintained at
> http://sourceforge.net/projects/geonetwork
>

_______________________________________________
GeoNetwork-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-users
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork
Reply | Threaded
Open this post in threaded view
|

Re: Access Geonetwork via Python-Skript

lmoeller
In reply to this post by Andreas Böhme
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
> [hidden email]
> 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: [hidden email]
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 

_______________________________________________
GeoNetwork-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-users
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork
Reply | Threaded
Open this post in threaded view
|

Re: Access Geonetwork via Python-Skript

Andreas Böhme
Thx for all the answers. I will try as you suggest.
All the best.
Andreas

Am 11.11.2020 um 10:03 schrieb Lars Möller:

> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/geonetwork-users
>> GeoNetwork OpenSource is maintained at
>> http://sourceforge.net/projects/geonetwork
>
--
--------------------------------------------------------------------------------------------
                                               
Andreas Böhme
Techniker/Technician
Landschaftsökologie/Computational Landscape Ecology
                               
Helmholtz-Zentrum für Umweltforschung GmbH - UFZ
Helmholtz Centre for Environmental Research GmbH - UFZ
Permoserstraße 15, 04318 Leipzig, Germany
Phone +49 341 235 1058
[hidden email], www.ufz.de

Sitz der Gesellschaft/Registered Office: Leipzig
Registergericht/Registration Office: Amtsgericht Leipzig
Handelsregister Nr./Trade Register Nr.: B 4703
Vorsitzender des Aufsichtsrats/Chairman of the Supervisory Board: N.N.
Wissenschaftlicher Geschäftsführer/Scientific Managing Director:
Prof. Dr. Georg Teutsch
Administrative Geschäftsführerin/Administrative Managing Director:
Dr. Sabine König

Vermeiden Sie unnötige Ausdrucke./Think before printing.

Informationen aus der Wissenschaft (z.B. Veranstaltungshinweise, Projektangaben, Publikationen,
Bücher)

--------------------------------------------------------------------------------------------




_______________________________________________
GeoNetwork-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-users
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork

smime.p7s (7K) Download Attachment