У меня есть запрос Python, который работает на API, который я пытаюсь использовать.
Я пытаюсь преобразовать его в Node js, но мне не удается выполнить запрос.
запрос Python:
import requests
url = 'https://simplivity@xxxx/api/'
hms_username = 'xxxx'
hms_password = 'xxxx'
response = requests.post(url+'oauth/token', auth=('simplivity', ''), verify=False, data={
'grant_type':'password',
'username':hms_username,
'password':hms_password})
print(response.json())
Узел JS запрос:
var https = require("https");
var options = {
host: "simplivity@xxxx",
path: "/api/oauth/token",
method: "POST",
headers: {
"Content-Type": "application/json",
}
};
var req = https.request(options, function (res) {
res.on("data", function (data) {
console.log(data);
});
res.on("end", function () {
console.log(data);
});
});
const data = JSON.stringify({
grant_type: 'password',
'username': 'xxxx',
'password': 'xxxx'
})
req.write(data);
req.end();
Я не понимаю, что я сделал не так между ними обоими.
Я не передал auth = 'simplivity' в узле js, потому что я не знаю, где его разместить.
Вот выходы:
питон:
tWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
{'access_token': 'xxxx', 'token_type': 'bearer', 'expires_in': 86399, 'scope': 'read write', 'updated_at': 1560771243707}
узел js:
events.js:174
throw er; // Unhandled 'error' event
^
Error: getaddrinfo EAI_FAIL simplivity@xxx simplivity@xxx:443
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
Emitted 'error' event at:
at TLSSocket.socketErrorListener (_http_client.js:392:9)
at TLSSocket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
[nodemon] app crashed - waiting for file changes before starting...
спасибо