Improved error handling, and improved uid-loading

Requests would sometimes throw an error while retrieving the c_user cookie (If there were multiple cookies with this name)
This commit is contained in:
Mads Marquart
2017-09-19 16:36:08 +02:00
parent 59ba418faa
commit ead9a3c0e9
2 changed files with 9 additions and 2 deletions

View File

@@ -157,7 +157,10 @@ class Client(object):
self.payloadDefault = {}
self.client_id = hex(int(random()*2147483648))[2:]
self.start_time = now()
self.uid = str(self._session.cookies['c_user'])
self.uid = self._session.cookies.get_dict().get('c_user')
if self.uid is None:
raise Exception('Could not find c_user cookie')
self.uid = str(self.uid)
self.user_channel = "p_" + self.uid
self.ttstamp = ''

View File

@@ -143,7 +143,11 @@ def graphql_queries_to_json(*queries):
return json.dumps(rtn)
def graphql_response_to_json(content):
content = strip_to_json(content) # Usually only needed in some error cases
try:
j = json.loads(content, cls=ConcatJSONDecoder)
except Exception as e:
raise Exception('Error while parsing JSON: {}'.format(repr(content)), e)
rtn = [None]*(len(j))
for x in j: