|
|
|
wgrunberg
|
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? -- _______________________________ Wolfgang Grunberg Arizona Geological Survey [hidden email] 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geonetwork-devel GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork |
||||||||||||||||
|
Francois Prunayre
|
Hello Wolfgang,
2009/10/19 Wolfgang Grunberg <[hidden email]>: > 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 > [hidden email] > 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 > [hidden email] > https://lists.sourceforge.net/lists/listinfo/geonetwork-devel > GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork > ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geonetwork-devel GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork |
||||||||||||||||
|
Alex Mandel-2
|
Yes please post and example, I'm interested in adding such a function to
a python metadata plugin in QGIS. Thanks, Alex Francois Prunayre wrote: > Hello Wolfgang, > > 2009/10/19 Wolfgang Grunberg <[hidden email]>: >> 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 >> [hidden email] >> 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 ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geonetwork-devel GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork |
||||||||||||||||
|
wgrunberg
|
In reply to this post
by Francois Prunayre
Some javascript/style in this post has been disabled (why?)
Attached is my sample GeoNetwork CSW transaction with authentication
Python script. I wrote it mostly to show how HTTP sessions could be
handled but I do not know if it is the best or even an appropriate
method.Where do I submit it for review? Should I just post it on the wiki? Ciao, WG _______________________________ Wolfgang Grunberg Arizona Geological Survey [hidden email] 520-770-3500 Francois Prunayre wrote: Hello Wolfgang, 2009/10/19 Wolfgang Grunberg [hidden email]: #!/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__ = "[hidden email]" __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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geonetwork-devel GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork |
||||||||||||||||
|
Francois Prunayre
|
2009/10/20 Wolfgang Grunberg <[hidden email]>:
> Attached is my sample GeoNetwork CSW transaction with authentication Python > script. I wrote it mostly to show how HTTP sessions could be handled but I > do not know if it is the best or even an appropriate method. > Where do I submit it for review? > Should I just post it on the wiki? I made an how-to on the wiki http://trac.osgeo.org/geonetwork/wiki/HowToDoCSWTransactionOperations Thanks Wolgang. Francois > Ciao, WG > > _______________________________ > Wolfgang Grunberg > Arizona Geological Survey > [hidden email] > 520-770-3500 > > > > Francois Prunayre wrote: > > Hello Wolfgang, > > 2009/10/19 Wolfgang Grunberg <[hidden email]>: > > > 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 > [hidden email] > 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 > [hidden email] > 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__ = "[hidden email]" > __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 > [hidden email] > https://lists.sourceforge.net/lists/listinfo/geonetwork-devel > GeoNetwork OpenSource is maintained at > http://sourceforge.net/projects/geonetwork > ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geonetwork-devel GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork |
||||||||||||||||
|
Andrew Watkins
|
Some javascript/style in this post has been disabled (why?)
NIWA is the trading name of the National Institute of Water &
Atmospheric Research Ltd.
------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geonetwork-devel GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork |
|||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |