I was wondering how to make a GET request to geoserver 2.6 in Python.
import urllib2, json
url = 'http://localhost:8080/geoserver/rest/workspaces.json'
authKey = 'admin:geoserver'
headers ={'Authorization': "Basic " + authKey}
params = {}
request = urllib2.Request(url, json.dumps(params), headers)
try:
response = urllib2.urlopen(request, timeout=30).read()
print json.loads(response)
except urllib2.HTTPError as e:
print e
print e.header
print e.read()
with code above, I get HTTP Error 500: Server Error. If I set the value of authKey to '', then I get "HTTP Error 401: Full authentication is required to access this resource"
So how can I set up the request header with authorization?
Update:
I print e.headers in the exception, then I got:
Date: Tue, 17 Mar 2015 15:33:04 GMT
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 6639
Connection: close
Server: Jetty(7.6.13.v20130916)