我正在尝试使用Web套接字从网站获取数据。这是我的代码
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.on('connectFailed', function(error) {
console.log('Connect Error: ' + error.toString());
});
client.on('connect', function(connection) {
console.log('WebSocket Client Connected');
connection.on('error', function(error) {
console.log("Connection Error: " + error.toString());
});
connection.on('close', function() {
console.log('echo-protocol Connection Closed');
});
connection.on('message', function(message) {
console.log("Received: '" + message + "'");
});
function sendNumber() {
if (connection.connected) {
connection.sendUTF(JSON.stringify({
key: 'Anisha$Hi'
}));
}
}
sendNumber();
});
client.connect('wss://sarthak999.pythonanywhere.com/', 'echo-protocol');
但是我收到连接错误addrnotfound。问题是什么?我想从URL中获取一些数据。这是我得到的错误:
Connect Error: Error: getaddrinfo ENOTFOUND sarthak999.pythonanywhere.com sarthak999.pythonanywhere.com:443
答案 0 :(得分:1)
您无法通过wss连接到pythonanywhere webapp(不支持)。