Skip to content

Commit

Permalink
Merge pull request #80 from Crunch-io/fix-401
Browse files Browse the repository at this point in the history
Return payload only on valid response
  • Loading branch information
zixan authored May 31, 2022
2 parents 45f9551 + 7ce6dfc commit 80e1ddd
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/pycrunch/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@ class Foo(Element):
"""

import json

import six
import warnings

import six
from requests.utils import get_environ_proxies

from pycrunch import lemonpy
from pycrunch.progress import DefaultProgressTracking

from .version import __version__

try:
# Python 2
from urllib import urlencode, quote
from urllib import quote, urlencode

from urlparse import urlparse
except ImportError:
# Python 3
from urllib.parse import urlencode, quote, urlparse
from urllib.parse import quote, urlencode, urlparse

omitted = object()

Expand Down Expand Up @@ -150,7 +151,10 @@ def __getattr__(self, key):
coll = self.get(collname, {})
if key in coll:
url = coll[key]
return self.session.get(url, headers=headers).payload
response = self.session.get(url, headers=headers)
if response.status_code not in {401}:
return response.payload
raise ValueError("Unauthorized")

raise AttributeError("%s has no attribute %s" % (self.__class__.__name__, key))

Expand Down Expand Up @@ -314,7 +318,12 @@ class ElementSession(lemonpy.Session):
handler_class = ElementResponseHandler

def __init__(
self, email=None, password=None, token=None, site_url=None, progress_tracking=None
self,
email=None,
password=None,
token=None,
site_url=None,
progress_tracking=None,
):
if not site_url and token:
raise ValueError("Must include a `site_url` host to connect to")
Expand Down

0 comments on commit 80e1ddd

Please sign in to comment.