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

properly handle 403 return codes from remote services #936

Open
landryb opened this issue Jul 9, 2024 · 0 comments
Open

properly handle 403 return codes from remote services #936

landryb opened this issue Jul 9, 2024 · 0 comments

Comments

@landryb
Copy link

landryb commented Jul 9, 2024

using 0.27.2 on debian 12, in some cases i'm creating a WebMapService object with an url that requires authentication, but i don't know that it requires auth yet. The object creation fails with a traceback related to lxml/etree:

Traceback (most recent call last):
  File "/home/landry/scratch/testmsorm/test.py", line 134, in <module>
    s = WebMapService(u, version='1.3.0')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/owslib/wms.py", line 54, in WebMapService
    return wms130.WebMapService_1_3_0(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/owslib/map/wms130.py", line 75, in __init__
    self._capabilities = reader.read(self.url, timeout=self.timeout)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/owslib/map/common.py", line 69, in read
    return etree.fromstring(raw_text)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "src/lxml/etree.pyx", line 3257, in lxml.etree.fromstring
  File "src/lxml/parser.pxi", line 1916, in lxml.etree._parseMemoryDocument
  File "src/lxml/parser.pxi", line 1803, in lxml.etree._parseDoc
  File "src/lxml/parser.pxi", line 1144, in lxml.etree._BaseParser._parseDoc
  File "src/lxml/parser.pxi", line 618, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 728, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 657, in lxml.etree._raiseParseError
  File "<string>", line 13
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 11 and head, line 13, column 8

i can of course catch that exception and handle it as "something failed" but in that case the server just returned a 403 code which is .. not handled by https://github.com/geopython/OWSLib/blame/master/owslib/util.py#L210

if i add 403 to that line, an owslib.util.ServiceException is raised. Should it be added to the list of codes ?

as a sidenote, req.text passed as the exception argument contains only the returned html, could it be more useful to have the complete request object (might contain credentials or sensitive env vars?), or at least the return code ?

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

No branches or pull requests

1 participant