Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise an error if GetCapabilities requests don't return XML #861

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

geographika
Copy link
Contributor

Currently if a GetCapabilities request doesn't return an XML document it raises cryptic error messages such as:

  File "owslib\feature\wfs200.py", line 164, in _buildMetadata
    for elem in self._capabilities.find(nspath("OperationsMetadata"))[:]:
TypeError: 'NoneType' object is not subscriptable

This pull request checks to see if the server response Content-Type is XML, and if not it raises an exception that includes the URL and response. If the response is HTML it attempts to parse the body of the document to use as the error message. This is particularly useful when working with MapServer which returns errors in text/html format. E.g.

http:///example.org/?service=WFS&request=GetCapabilities&version=2.0.0 responded 
with Content-Type 'text/html': 'msCGILoadMap(): Web application error. CGI variable "map" is not set.'

Currently any Content-Type which has any match/partial match against the following list will be considered as XML: ['text/xml', 'application/xml', 'application/vnd.ogc.wms_xml']

It may be better to just check for xml in case there are types I've missed?

In addition the strip_bom was only previously used for WMS GetCapabilities requests - this change means it is applied to all service types (WFS, SOS, WCS, WMTS).

@coveralls
Copy link

coveralls commented Feb 13, 2023

Coverage Status

Coverage: 59.561% (+0.04%) from 59.523% when pulling 7890a58 on geographika:getcapabilities-errors into 306ceed on geopython:master.

@geographika geographika reopened this Apr 10, 2023
Copy link

github-actions bot commented Oct 6, 2024

This Pull Request has been inactive for 90 days. In order to manage maintenance burden, it will be automatically closed in 7 days.

@github-actions github-actions bot added the stale label Oct 6, 2024
@coveralls
Copy link

Coverage Status

coverage: 60.189% (+0.5%) from 59.725%
when pulling 58f7a29 on geographika:getcapabilities-errors
into f620405 on geopython:master.

@geographika
Copy link
Contributor Author

Rebased against main - all tests passing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants