Browse Source

Adding getUserId

Andrej 4 years ago
parent
commit
a4400ee174
1 changed files with 13 additions and 0 deletions
  1. 13 0
      labkeyInterface.py

+ 13 - 0
labkeyInterface.py

@@ -63,6 +63,8 @@ class labkeyInterface:
         #f contains json as a return value
         except urllib3.exceptions.HTTPError as e:
             print(e)
+            #useful for querying code
+            return e
 
     def head(self,url):
 
@@ -75,6 +77,9 @@ class labkeyInterface:
             return self.http.request('HEAD',url,headers=headers)
         except urllib3.exceptions.HTTPError as e:
             print(e)
+            #usefule for querying code
+            return e
+
 
 
     def post(self,url,data):
@@ -137,6 +142,14 @@ class labkeyInterface:
         jsonData=json.loads(response.data.decode(encoding))
         return jsonData["CSRF"]
 
+    def getUserId(self):
+        url=self.GetLabkeyUrl()+'/login/whoAmI.view'
+        response=self.get(url)
+        self.cookie=response.getheader('Set-Cookie')
+        encoding=chardet.detect(response.data)['encoding']
+        jsonData=json.loads(response.data.decode(encoding))
+        return jsonData["id"]
+