Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 正在尝试将我的socketio客户端从js移植到python,但它不起作用_Javascript_Python_Websocket_Socket.io_Client - Fatal编程技术网

Javascript 正在尝试将我的socketio客户端从js移植到python,但它不起作用

Javascript 正在尝试将我的socketio客户端从js移植到python,但它不起作用,javascript,python,websocket,socket.io,client,Javascript,Python,Websocket,Socket.io,Client,我有以下JS代码,可以通过socketio客户端库连接到套接字: userApi = 'userapiaccesfskdglk'; userAccess = 'useaccesfjkasdfdlkf2'; var axios = require('axios'); var socket = require('socket.io-client')('wss://test-meownow12345.com:4566'); socket.emit('Authenticate', {api: use

我有以下JS代码,可以通过socketio客户端库连接到套接字:

userApi = 'userapiaccesfskdglk';
userAccess = 'useaccesfjkasdfdlkf2';

var axios = require('axios');
var socket = require('socket.io-client')('wss://test-meownow12345.com:4566');

socket.emit('Authenticate', {api: userApi, access: userAccess});

socket.on('Party', function(party) {
    console.log('party', party)

})
这些不是实际使用的userApi、userAccess或url,但使用它们仍然可以获得相同的结果

这就是我在python中拥有的功能,在我看来,它就像一个精确的端口,但不起作用:

from socketIO_client import SocketIO, LoggingNamespace
import logging
logging.basicConfig(level=logging.DEBUG)


def on_party():
    print('connect')

userApi = 'userapiaccesfskdglk'
userAccess = 'useaccesfjkasdfdlkf2'

with SocketIO('wss://test-meownow12345.com', 4566, LoggingNamespace) as socketIO:
    socketIO.emit('Authenticate', {'api': userApi, 'access': userAccess})
    socketIO.on('Party', on_party)
这似乎是等效的,但显然不是,因为代码无法通过打开socket.io连接的以下行:

with SocketIO('wss://test-meownow12345.com', 4566, LoggingNamespace) as socketIO:
在我的控制台中,它打印出以下重复的日志错误:

DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): wss
WARNING:socketIO-client:wss:4566//test-meownow12345.com/socket.io [engine.io waiting for connection] HTTPConnectionPool(host='wss', port=4566): Max retries exceeded with url: //test-meownow12345.com/socket.io/?EIO=3&transport=polling&t=1523668232386-0 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105000278>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
但这仍然失败,尽管日志中有一条新消息重复:

DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): test-meownow12345.com
WARNING:socketIO-client:test-meownow12345.com:4566/socket.io [engine.io waiting for connection] ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
DEBUG:urllib3.connectionpool:Starting new HTTP connection (2): test-meownow12345.com
DEBUG:urllib3.connectionpool:Starting new HTTP connection (3): test-meownow12345.com

非常感谢您的帮助,这是一个非常令人沮丧的问题。

如果您查看
SocketIO

class SocketIO(EngineIO):
它继承自
EngineIO
,它具有
\uuuu init\uuuu
作为

class EngineIO(LoggingMixin):

    def __init__(
            self, host, port=None, Namespace=EngineIONamespace,
            wait_for_connection=True, transports=TRANSPORTS,
            resource='engine.io', hurry_interval_in_seconds=1, **kw):
        self._is_secure, self._url = parse_host(host, port, resource)
        self._wait_for_connection = wait_for_connection
parse_host
的定义是

def parse_host(host, port, resource):
    if not host.startswith('http'):
        host = 'http://' + host
    url_pack = parse_url(host)
    is_secure = url_pack.scheme == 'https'
    port = port or url_pack.port or (443 if is_secure else 80)
    url = '%s:%s%s/%s' % (url_pack.hostname, port, url_pack.path, resource)
    return is_secure, url
这表明用法如下所示

with SocketIO('https://test-meownow12345.com', 4566, LoggingNamespace) as socketIO:
    socketIO.emit('Authenticate', {'api': userApi, 'access': userAccess})
    socketIO.on('Party', on_party)

你打开4566端口了吗?请尝试
$telnet test-meownow12345.com 4566
@Quỳ恩古伊ễn我会试试这个,但它与JS一起工作的事实不意味着端口是开放的吗?我只是猜测,因为您的源代码似乎还可以。@MarkKeane,请使用SocketIO('https://test-meownow12345.com“,4566,LoggingNamespace)作为socketIO:。看看库代码,这似乎是他们所期望的
with SocketIO('https://test-meownow12345.com', 4566, LoggingNamespace) as socketIO:
    socketIO.emit('Authenticate', {'api': userApi, 'access': userAccess})
    socketIO.on('Party', on_party)