Skip to content

How to load WMS protected with username and password? #884

Answered by giswqs
aborruso asked this question in Q&A
Discussion options

You must be logged in to vote

From ChatGPT. Not sure if it works. If not, it is an ipyleaflet issue.

import ipyleaflet
from ipywidgets import HTML

# Define your WMS service URL and credentials
wms_url = "https://ogc-dev.sample.eu/geoserver/iride/wms?"
username = "your_username"
password = "your_password"

# Create a basic authentication header
auth_header = f"Basic {username}:{password}"

# Create the WMS layer
wms_layer = ipyleaflet.WMSLayer(
    url=wms_url,
    layers='your_layer_name',
    format='image/png',
    transparent=True,
    attribution='WMS Service',
    # Add the custom headers here
    headers={'Authorization': auth_header}
)

# Create a map
m = ipyleaflet.Map(center=(0, 0), zoom=2)

# Add the WMS la…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@aborruso
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by giswqs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants