502 错误网关 - 调用评分 api 端点
502 Bad Gateway - calling scoring api endpoint
我正在使用社区笔记本中的以下代码使用 IBM Watson Machine Learning 预测户外设备购买:
...
<code omitted for brevity>
...
import urllib3, requests, json
headers = urllib3.util.make_headers(basic_auth='{}:{}'.format(username, password))
url = '{}/v2/identity/token'.format(service_path)
response = requests.get(url, headers=headers)
mltoken = json.loads(response.text).get('token')
endpoint_online = service_path + "/v2/online/deployments/"
header_online = {'Content-Type': 'application/json', 'Authorization': mltoken}
payload_online = {"artifactVersionHref": saved_model.meta.prop("modelVersionHref"), "name": "Product Line Prediction"}
response_online = requests.post(endpoint_online, json=payload_online, headers=header_online)
print response_online
print response_online.text
scoring_href = json.loads(response_online.text).get('entity').get('scoringHref')
print scoring_href
回应
<Response [201]>
{"metadata":{"guid":"4148","href":"https://ibm-watson-ml.mybluemix.net/v2/online/deployments/4148","createdAt":"2017-06-13T07:54:16.062Z","modifiedAt":"2017-06-13T07:54:16.062Z"},"entity":{"scoringHref":"https://ibm-watson-ml.mybluemix.net/32768/v2/scoring/4148"}}
https://ibm-watson-ml.mybluemix.net/32768/v2/scoring/4148
下次尝试得分:
payload_scoring = {"record":["M", 23, "Single", "Student"]}
response_scoring = requests.put(scoring_href, json=payload_scoring, headers=header_online)
print response_scoring.text
回复:
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.10.1</center>
</body>
</html>
几分钟后我再次尝试调用,调用成功:
{
"result":{
"PROFESSION_IX":6.0,
"GENDER_IX":0.0,
"MARITAL_STATUS_IX":1.0,
"GENDER":"M",
"features":{
"values":[
0.0,
23.0,
1.0,
6.0
]
},
"predictedLabel":"Personal Accessories",
"prediction":1.0,
...
}
我正在使用社区笔记本中的以下代码使用 IBM Watson Machine Learning 预测户外设备购买:
...
<code omitted for brevity>
...
import urllib3, requests, json
headers = urllib3.util.make_headers(basic_auth='{}:{}'.format(username, password))
url = '{}/v2/identity/token'.format(service_path)
response = requests.get(url, headers=headers)
mltoken = json.loads(response.text).get('token')
endpoint_online = service_path + "/v2/online/deployments/"
header_online = {'Content-Type': 'application/json', 'Authorization': mltoken}
payload_online = {"artifactVersionHref": saved_model.meta.prop("modelVersionHref"), "name": "Product Line Prediction"}
response_online = requests.post(endpoint_online, json=payload_online, headers=header_online)
print response_online
print response_online.text
scoring_href = json.loads(response_online.text).get('entity').get('scoringHref')
print scoring_href
回应
<Response [201]>
{"metadata":{"guid":"4148","href":"https://ibm-watson-ml.mybluemix.net/v2/online/deployments/4148","createdAt":"2017-06-13T07:54:16.062Z","modifiedAt":"2017-06-13T07:54:16.062Z"},"entity":{"scoringHref":"https://ibm-watson-ml.mybluemix.net/32768/v2/scoring/4148"}}
https://ibm-watson-ml.mybluemix.net/32768/v2/scoring/4148
下次尝试得分:
payload_scoring = {"record":["M", 23, "Single", "Student"]}
response_scoring = requests.put(scoring_href, json=payload_scoring, headers=header_online)
print response_scoring.text
回复:
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.10.1</center>
</body>
</html>
几分钟后我再次尝试调用,调用成功:
{
"result":{
"PROFESSION_IX":6.0,
"GENDER_IX":0.0,
"MARITAL_STATUS_IX":1.0,
"GENDER":"M",
"features":{
"values":[
0.0,
23.0,
1.0,
6.0
]
},
"predictedLabel":"Personal Accessories",
"prediction":1.0,
...
}