0
我正在學習Python,並遇到奇怪的問題。我在我的macOS Sierra本地盒子上運行RabitMQ。從python腳本連接到RabbitMQ服務器總是失敗,併發生套接字超時錯誤。同時我可以通過telnet連接。 運行的Python 2.7和庫海帶:無法從Python連接到RabbitMQ
# test.py
from kombu import Connection
connection = Connection('amqp://127.0.0.1')
connection.connect()
結果:
Thunderstorm:test max$ python test.py
Traceback (most recent call last):
File "test.py", line 6, in <module>
connection.connect()
File "/Library/Python/2.7/site-packages/kombu/connection.py", line 261, in connect
return self.connection
File "/Library/Python/2.7/site-packages/kombu/connection.py", line 802, in connection
self._connection = self._establish_connection()
File "/Library/Python/2.7/site-packages/kombu/connection.py", line 757, in _establish_connection
conn = self.transport.establish_connection()
File "/Library/Python/2.7/site-packages/kombu/transport/pyamqp.py", line 130, in establish_connection
conn.connect()
File "/Library/Python/2.7/site-packages/amqp/connection.py", line 300, in connect
self.drain_events(timeout=self.connect_timeout)
File "/Library/Python/2.7/site-packages/amqp/connection.py", line 464, in drain_events
return self.blocking_read(timeout)
File "/Library/Python/2.7/site-packages/amqp/connection.py", line 468, in blocking_read
frame = self.transport.read_frame()
File "/Library/Python/2.7/site-packages/amqp/transport.py", line 237, in read_frame
frame_header = read(7, True)
File "/Library/Python/2.7/site-packages/amqp/transport.py", line 377, in _read
s = recv(n - len(rbuf))
socket.timeout: timed out
這需要幾秒鐘,然後返回超時。此時在RabbitMq日誌中,我看到:
=INFO REPORT==== 1-Mar-2017::12:25:00 ===
accepting AMQP connection <0.23773.4> (127.0.0.1:60600 -> 127.0.0.1:5672)
=WARNING REPORT==== 1-Mar-2017::12:25:08 ===
closing AMQP connection <0.23773.4> (127.0.0.1:60600 -> 127.0.0.1:5672):
client unexpectedly closed TCP connection
防火牆已關閉。 Telnet連接成功:
Thunderstorm:test max$ telnet 127.0.0.1 5672
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
如何調試此問題?
你試圖把在連接的端口號作爲你的遠程登錄?即'Connection('amqp://127.0.0.1:5672')' – Dillanm
是的,我用端口,默認憑據,但總是得到相同的結果。 '連接('amqp://127.0.0.1:5672')''連接('amqp:// guest:[email protected]:5672')' –