From 2197cd371bdef331fa19b5d1645a8ce0ec5f51ec Mon Sep 17 00:00:00 2001 From: zixan Date: Thu, 26 May 2022 04:18:39 -0400 Subject: [PATCH 1/2] Update elements.py --- src/pycrunch/elements.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pycrunch/elements.py b/src/pycrunch/elements.py index b6eb29a..d6a373d 100644 --- a/src/pycrunch/elements.py +++ b/src/pycrunch/elements.py @@ -150,7 +150,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(response.json()["exception"][0]) raise AttributeError("%s has no attribute %s" % (self.__class__.__name__, key)) From 7ce6dfca46310893c57ff2b8da04d514c1ba5ff8 Mon Sep 17 00:00:00 2001 From: Zeeshan Mughal Date: Fri, 27 May 2022 03:46:29 -0400 Subject: [PATCH 2/2] Fix error message --- src/pycrunch/elements.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pycrunch/elements.py b/src/pycrunch/elements.py index d6a373d..10bb139 100644 --- a/src/pycrunch/elements.py +++ b/src/pycrunch/elements.py @@ -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() @@ -153,7 +154,7 @@ def __getattr__(self, key): response = self.session.get(url, headers=headers) if response.status_code not in {401}: return response.payload - raise ValueError(response.json()["exception"][0]) + raise ValueError("Unauthorized") raise AttributeError("%s has no attribute %s" % (self.__class__.__name__, key)) @@ -317,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")