2017-01-17 22 views
0

私はローカルホスト上で実行中のサービスに接続するのWebSocketを書くしようとしているが、それはエラーを投げPythonのWebSocketをエラーgaierror

>>> from websocket import create_connection 
>>> ws = create_connection("ws://127.0.0.1", http_proxy_port="2974", http_proxy_host="quividicontent") 

Traceback (most recent call last): 
    File "<pyshell#24>", line 1, in <module> 
    ws = create_connection("ws://127.0.0.1", http_proxy_port="2974", http_proxy_host="quividicontent") 
    File "C:\Python27\lib\websocket\_core.py", line 487, in create_connection 
    websock.connect(url, **options) 
    File "C:\Python27\lib\websocket\_core.py", line 211, in connect 
    options.pop('socket', None)) 
    File "C:\Python27\lib\websocket\_http.py", line 64, in connect 
    hostname, port, is_secure, proxy) 
    File "C:\Python27\lib\websocket\_http.py", line 97, in _get_addrinfo_list 
    addrinfo_list = socket.getaddrinfo(phost, pport, 0, 0, socket.SOL_TCP) 
gaierror: [Errno 11001] getaddrinfo failed 
>>> ws = create_connection("ws://127.0.0.1", http_proxy_port="2974") 

Traceback (most recent call last): 
    File "<pyshell#25>", line 1, in <module> 
    ws = create_connection("ws://127.0.0.1", http_proxy_port="2974") 
    File "C:\Python27\lib\websocket\_core.py", line 487, in create_connection 
    websock.connect(url, **options) 
    File "C:\Python27\lib\websocket\_core.py", line 214, in connect 
    self.handshake_response = handshake(self.sock, *addrs, **options) 
    File "C:\Python27\lib\websocket\_handshake.py", line 65, in handshake 
    status, resp = _get_resp_headers(sock) 
    File "C:\Python27\lib\websocket\_handshake.py", line 122, in _get_resp_headers 
    raise WebSocketBadStatusException("Handshake status %d", status) 
WebSocketBadStatusException: Handshake status 200 
>>> import socket 
>>> socket.getaddrinfo('localhost', 2974) 
[(23, 0, 0, '', ('::1', 2974, 0, 0)), (2, 0, 0, '', ('127.0.0.1', 2974))] 

私はポートがソケットを使用し、オープンでリスニングあると確信しているとonOpenonMessage関数のより複雑な例が機能します。

+0

する必要がありますあなたは 'を使用して' create_connection'を更新しようとすることができます"ws://127.0.0.1:2974"。 '' ws://127.0.0.1:2974/your/ressource '' – iFlo

+0

と同じリソースを持っていれば、最終的に' gaierror:[Errno 11001] getaddrinfo failed'を返します –

+0

接続しようとするとWebSocketを管理できますか? – iFlo

答えて

0

websocketでハンドシェイクのプロトコルを指定する必要があるため、問題が発生します。 wikipediaから

:このハンドシェイク中

To establish a WebSocket connection, the client sends a WebSocket handshake request, for which the server returns a WebSocket handshake response, as shown in the example below.

、サーバとクライアントのプロトコルを使用すべきかについて議論し、指定された何のプロトコルが存在しない場合、これはエラー(常にではない)につながる可能性があります。 python-WebSocketのドキュメントから

、プロトコルを指定するには、 で行うことができます:あなたの特定のケースで

ws = websocket.create_connection("ws://exapmle.com/websocket", subprotocols=["binary", "base64"]) 

subprotocols['quividicontent']

関連する問題