|
11 | 11 | from licensing.internal import HelperMethods |
12 | 12 | from licensing.models import * |
13 | 13 | import json |
| 14 | +from urllib.error import URLError, HTTPError |
14 | 15 |
|
15 | 16 | class Key: |
16 | 17 |
|
@@ -44,8 +45,12 @@ def activate(token, rsa_pub_key, product_id, key, machine_code, fields_to_return |
44 | 45 | "MaxOverdraft": max_overdraft,\ |
45 | 46 | "Sign":"True",\ |
46 | 47 | "SignMethod":1})) |
| 48 | + except HTTPError as e: |
| 49 | + response = Response.from_string(e.read()) |
| 50 | + except URLError as e: |
| 51 | + return (None, "Could not contact the server. Error message: " + e.reason) |
47 | 52 | except Exception: |
48 | | - return (None, "Could not contact the server.") |
| 53 | + return (None, "Could not contact the server. Error message: " + e.reason) |
49 | 54 |
|
50 | 55 | pubkey = RSAPublicKey.from_string(rsa_pub_key) |
51 | 56 |
|
@@ -83,8 +88,12 @@ def get_key(token, rsa_pub_key, product_id, key, fields_to_return = 0,\ |
83 | 88 | "FloatingTimeInterval": floating_time_interval,\ |
84 | 89 | "Sign":"True",\ |
85 | 90 | "SignMethod":1})) |
| 91 | + except HTTPError as e: |
| 92 | + response = Response.from_string(e.read()) |
| 93 | + except URLError as e: |
| 94 | + return (None, "Could not contact the server. Error message: " + e.reason) |
86 | 95 | except Exception: |
87 | | - return (None, "Could not contact the server.") |
| 96 | + return (None, "Could not contact the server. Error message: " + e.reason) |
88 | 97 |
|
89 | 98 | pubkey = RSAPublicKey.from_string(rsa_pub_key) |
90 | 99 |
|
@@ -115,8 +124,12 @@ def create_trial_key(token, product_id, machine_code): |
115 | 124 | response = HelperMethods.send_request("key/createtrialkey", {"token":token,\ |
116 | 125 | "ProductId":product_id,\ |
117 | 126 | "MachineCode":machine_code}) |
| 127 | + except HTTPError as e: |
| 128 | + response = Response.from_string(e.read()) |
| 129 | + except URLError as e: |
| 130 | + return (None, "Could not contact the server. Error message: " + e.reason) |
118 | 131 | except Exception: |
119 | | - return (None, "Could not contact the server.") |
| 132 | + return (None, "Could not contact the server. Error message: " + e.reason) |
120 | 133 |
|
121 | 134 | jobj = json.loads(response) |
122 | 135 |
|
@@ -146,8 +159,12 @@ def deactivate(token, product_id, key, machine_code, floating = False): |
146 | 159 | "Key" : key,\ |
147 | 160 | "Floating" : floating,\ |
148 | 161 | "MachineCode":machine_code}) |
| 162 | + except HTTPError as e: |
| 163 | + response = Response.from_string(e.read()) |
| 164 | + except URLError as e: |
| 165 | + return (None, "Could not contact the server. Error message: " + e.reason) |
149 | 166 | except Exception: |
150 | | - return (False, "Could not contact the server.") |
| 167 | + return (None, "Could not contact the server. Error message: " + e.reason) |
151 | 168 |
|
152 | 169 | jobj = json.loads(response) |
153 | 170 |
|
|
0 commit comments