Thanks Wolgang.
Ciao, WG
_______________________________
Wolfgang Grunberg
Arizona Geological Survey
wgrunberg@anonymised.com
520-770-3500
Francois Prunayre wrote:
Hello Wolfgang,
2009/10/19 Wolfgang Grunberg <wgrunberg@anonymised.com>:
Hi,
I have several metadata ETL Python scripts that generate CSW AP ISO
insert transactions (XML through HTTP Post).
Is there a way to login to GeoNewtork through a Post request?
You cannot do that in one step for the time being. You need to create
a session and login first using xml.user.login service.
Have a look to this example in JS
https://geonetwork.svn.sourceforge.net/svnroot/geonetwork/trunk/web/geonetwork/scripts/test-csw.js
loginAndRun method.
If you've an example to do that in python, it could be nice to put
this example in the wiki ?
HTH.
Francois
--
_______________________________
Wolfgang Grunberg
Arizona Geological Survey
wgrunberg@anonymised.com
520-770-3500
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoNetwork-devel mailing list
GeoNetwork-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
GeoNetwork OpenSource is maintained at
http://sourceforge.net/projects/geonetwork
#!/usr/bin/env python
# this is gn_csw_transaction_example.py
"""
Example CSW 2.0.2 transaction with authentication Python script for
GeoNetwork
Tested with GeoNetwork 2.4.1 on Windows
Python 2.6
Wolfgang Grunberg
Arizona Geological Survey
10/20/2009
"""
# Library Imports
import urllib
import urllib2
import cookielib
# module globals and constants
__author__ = "Wolfgang Grunberg"
__credits__ = ["Wolfgang Grunberg", "the Internets"]
__email__ = "wgrunberg@anonymised.com"
__status__ = "Prototype" # "Prototype", "Development", or
"Production"
# GeoNetwork constants
gn_username = "admin"
gn_password = "admin"
gn_baseURL = "http://localhost:8080"
gn_loginURI = "/geonetwork/srv/en/xml.user.login"
gn_logoutURI = "/geonetwork/srv/en/xml.user.logout"
gn_cswURI = "/geonetwork/srv/en/csw"
def gn_csw_transaction():
"""
Execute GeoNetwork authentication and CSW transaction post
"""
# HTTP header for authentication
header_urlencode = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
# HTTP header for CSW request
header_xml = {"Content-type": "application/xml", "Accept": "text/plain"}
# authentication Post parameters
post_parameters = urllib.urlencode({"username": gn_username, "password":
gn_password})
# Sample CSW transactions
xml_request = "<?xml version=\"1.0\"?>\
<csw:DescribeRecord
xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\\"\\
service=\"CSW\" version=\"2.0.2\"
outputFormat=\"application/xml\"\
schemaLanguage=\"http://www.w3.org/XML/Schema\\"/>"
# log in URL
url_in = gn_baseURL+gn_loginURI
# log out URL
url_out = gn_baseURL+gn_logoutURI
# CSW URL
url_csw = gn_baseURL+gn_cswURI
# first, always log out
request = urllib2.Request(url_out)
response = urllib2.urlopen(request)
#print response.read() # debug
# send authentication request
request = urllib2.Request(url_in, post_parameters, header_urlencode)
response = urllib2.urlopen(request)
# a basic memory-only cookie jar instance
cookies = cookielib.CookieJar()
cookies.extract_cookies(response,request)
cookie_handler= urllib2.HTTPCookieProcessor( cookies )
# a redirect handler
redirect_handler= urllib2.HTTPRedirectHandler()
# save cookie and redirect handler for future HTTP Posts
opener = urllib2.build_opener(redirect_handler,cookie_handler)
# CSW request
request = urllib2.Request(url_csw, xml_request2, header_xml)
response = opener.open(request)
# CSW respons
xml_response = response.read()
print xml_response # debug
# Do something with the response. For example:
#xmldoc = minidom.parseString(xml_response)
#for node in xmldoc.getElementsByTagName('ows:ExceptionText'): #
display <ows:ExceptionText /> value(s)
# print " EXCEPTION: "+node.firstChild.nodeValue
#xmldoc.unlink() # cleanup DOM for improved performance
# more CSW requests if desired
# Last, alaways log out
request = urllib2.Request(url_out)
response = urllib2.urlopen(request)
#print response.read() # debug
if __name__=="__main__":
gn_csw_transaction()
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoNetwork-devel mailing list
GeoNetwork-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
GeoNetwork OpenSource is maintained at
http://sourceforge.net/projects/geonetwork