簡體   English   中英

無法從Python連接到RabbitMQ

[英]Could not connect to RabbitMQ from Python

我正在學習Python,卻遇到了奇怪的問題。 我在macOS Sierra本地機器上運行RabitMQ。 從python腳本連接到RabbitMQ服務器總是失敗,並出現套接字超時錯誤。 同時,我可以通過telnet連接。 運行Python 2.7和庫kombu:

# 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/', connect_timeout=15)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM