-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrackApi.py
More file actions
28 lines (24 loc) · 1.08 KB
/
trackApi.py
File metadata and controls
28 lines (24 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import urllib.request
class TrackingApi:
apiKey = "Your api key"
apiPath = ""
baseApi = "https://api.trackingmore.com"
apiVersion = "v3"
sandbox = False
def __init__(self, api_key):
self.apiKey = api_key
def doRequest(self, api_path, post_data="", method="get"):
method = method.upper()
if self.sandbox:
url = self.baseApi + "/" + self.apiVersion + "/trackings/sandbox/" + api_path
else:
url = self.baseApi + "/" + self.apiVersion + "/trackings/" + api_path
print("Request url: %s " % url)
headers = {"Content-Type": "application/json", "Tracking-Api-Key": self.apiKey,
'User-Agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) '
'Chrome/24.0.1312.27 Safari/537.17'}
post_data = post_data.encode('UTF-8')
req = urllib.request.Request(url, post_data, headers=headers, method=method)
with urllib.request.urlopen(req) as response:
print(response.getcode())
return response.read()