Whenever i think I understand encodings, I don't.. How do I correctly send a layername to the getmap function?
running python 2.7
from owslib.wms import WebMapService
wms_url = "http://ext-geodata.lansstyrelsen.se/arcgis/services/WMS/LST_WMS_riksintressen_3_5_st/mapserver/wmsserver?"
wms = WebMapService(wms_url)
my_layer = list(wms.contents)[1]
#output = u'ST Riksintresse K\xe4rnomr\xe5de MB3kap5'
img = wms.getmap(layers=[my_layer],
styles=['default'],
srs='EPSG:3006',
bbox=(7000000,577000,7113000,690000),
size=(500, 500),
format='image/png',
transparent=True
)
out = open('testarea.png', 'wb')
out.write(img.read())
out.close()
When I run this, I get a UnicodeEncodeError. I understand I need to encode the layername correctly, but I fail to understand how.
l = my_layer.encode('utf-8')
img = wms.getmap(layers=[l], #etc etc...
yields
ServiceException: Parameter 'layers' contains unacceptable layer names.
How do I parse values from the contents list to layername correctly?