forked from thzandvl/microhack-sap-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestForecast.py
66 lines (57 loc) · 2.19 KB
/
testForecast.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import urllib.request
import json
import os
import ssl
def allowSelfSignedHttps(allowed):
# bypass the server certificate verification on client side
if allowed and not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None):
ssl._create_default_https_context = ssl._create_unverified_context
allowSelfSignedHttps(True) # this line is needed if you use self-signed certificate in your scoring service.
data = {
"data":
[
{
"CUSTOMERNAME": "Westend Cycles",
"CUSTOMERGROUP": "Z1",
"BILLINGCOMPANYCODE": 1710,
"CUSTOMERACCOUNTGROUP": "KUNA",
"CREDITCONTROLAREA": "A000",
"DISTRIBUTIONCHANNEL": 10,
"ORGANIZATIONDIVISION": 0,
"SALESDISTRICT": "US0003",
"SALESORGANIZATION": 1710,
"SDDOCUMENTCATEGORY": "C",
"CITYNAME": "RALEIGH",
"POSTALCODE": "27603"
},
{
"CUSTOMERNAME": "Skymart Corp",
"CUSTOMERGROUP": "Z2",
"BILLINGCOMPANYCODE": 1710,
"CUSTOMERACCOUNTGROUP": "KUNA",
"CREDITCONTROLAREA": "A000",
"DISTRIBUTIONCHANNEL": 10,
"ORGANIZATIONDIVISION": 0,
"SALESDISTRICT": "US0004",
"SALESORGANIZATION": 1710,
"SDDOCUMENTCATEGORY": "C",
"CITYNAME": "New York",
"POSTALCODE": "10007"
}
],
}
body = str.encode(json.dumps(data))
#Replace with your own url
url = 'http://2fe78f13-726c-43d0-9182-7e0b084a295b.westeurope.azurecontainer.io/score'
api_key = '' # Replace this with the API key for the web service if needed
headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ api_key)}
req = urllib.request.Request(url, body, headers)
try:
response = urllib.request.urlopen(req)
result = response.read()
print(result)
except urllib.error.HTTPError as error:
print("The request failed with status code: " + str(error.code))
# Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
print(error.info())
print(json.loads(error.read().decode("utf8", 'ignore')))