Mercurial > hg > orthanc
comparison Resources/Samples/Python/RestToolbox.py @ 424:76bc8770741b
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 08 May 2013 11:13:48 +0200 |
parents | 4d76fce206ef |
children | 44382c8bcd15 |
comparison
equal
deleted
inserted
replaced
423:3c4a0e85c1da | 424:76bc8770741b |
---|---|
11 def _SetupCredentials(h): | 11 def _SetupCredentials(h): |
12 global _credentials | 12 global _credentials |
13 if _credentials != None: | 13 if _credentials != None: |
14 h.add_credentials(_credentials[0], _credentials[1]) | 14 h.add_credentials(_credentials[0], _credentials[1]) |
15 | 15 |
16 def DoGet(uri, data = {}): | 16 def DoGet(uri, data = {}, interpretAsJson = True): |
17 d = '' | 17 d = '' |
18 if len(data.keys()) > 0: | 18 if len(data.keys()) > 0: |
19 d = '?' + urlencode(data) | 19 d = '?' + urlencode(data) |
20 | 20 |
21 h = httplib2.Http() | 21 h = httplib2.Http() |
22 _SetupCredentials(h) | 22 _SetupCredentials(h) |
23 resp, content = h.request(uri + d, 'GET') | 23 resp, content = h.request(uri + d, 'GET') |
24 if not (resp.status in [ 200 ]): | 24 if not (resp.status in [ 200 ]): |
25 raise Exception(resp.status) | 25 raise Exception(resp.status) |
26 elif not interpretAsJson: | |
27 return content | |
26 else: | 28 else: |
27 try: | 29 try: |
28 return json.loads(content) | 30 return json.loads(content) |
29 except: | 31 except: |
30 return content | 32 return content |