Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Raise specific exception for bad auth. #155

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions shareplum/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from lxml import etree
# import defusedxml.ElementTree as etree

from .errors import ShareplumRequestError
from .request_helper import get, post
from .list import _List2007, _List365
from .folder import _Folder
Expand Down Expand Up @@ -338,12 +339,22 @@ def get_users(self, rowlimit=0):
self.last_request = str(soap_request)

# Send Request
response = post(self._session,
url=self._url("Lists"),
headers=self._headers("GetListItems"),
data=str(soap_request).encode("utf-8"),
verify=self._verify_ssl,
timeout=self.timeout)
response = self._session.post(self._url("Lists"),
headers=self._headers("GetListItems"),
data=str(soap_request).encode("utf-8"),
verify=self._verify_ssl,
timeout=self.timeout,
)
if response.status_code == 404 and requests.post(self._url("Lists")).status_code == 200:
msg = ("get_users received a 404 for the SOAP request "
"even though the URL {} is accessible; this error code in this context means "
"the authorization is bad.".format(self._url("Lists")))
if hasattr(self._session, 'auth') and hasattr(self._session.auth, 'domain'):
msg += " Domain = {}".format(self._session.auth.domain)
if hasattr(self._session, 'auth') and hasattr(self._session.auth, 'username'):
msg += " Username = {}".format(self._session.auth.username)
raise ShareplumRequestError(msg)
response.raise_for_status()

# Parse Response
try:
Expand Down