gpt4 book ai didi

python - 如何连接 Vagrant 主机上的兔子?

转载 作者:行者123 更新时间:2023-12-03 08:54:48 24 4
gpt4 key购买 nike

我在虚拟机上使用 vagrant 设置了服务器。安装rabbitmq后,我尝试使用虚拟机外部的脚本连接到它。 VM 上已经运行了 Django 和 RabbitMQ。运行脚本后出现异常:

pika.exceptions.IncompatibleProtocolError: StreamLostError: ('Transport indicated EOF',)

如何解决我的问题?

我的 friend 已经在 raspberryPi 上使用了下面提供的代码,它实际上成功地执行了它。我在 PC 上唯一更改的是将主机名从指定的 IP 更改为“127.0.0.1”,并添加了端口号。

import pika
import sys
import random
import time


credentials = pika.PlainCredentials(username='admin', password='admin')
connection = pika.BlockingConnection(pika.ConnectionParameters(host='127.0.0.1',port=15672,credentials=credentials))

channel = connection.channel()
channel.queue_declare(queue='hello',durable=True)

错误消息:

$ python send.py
Traceback (most recent call last):
File "send.py", line 8, in <module>
connection = pika.BlockingConnection(pika.ConnectionParameters(host='127.0.0.1',port=15672,credentials=credentials))
File "C:\Users\Pigeonnn\AppData\Local\Programs\Python\Python37\lib\site-packages\pika\adapters\blocking_connection.py", line 360, in __init__
self._impl = self._create_connection(parameters, _impl_class)
File "C:\Users\Pigeonnn\AppData\Local\Programs\Python\Python37\lib\site-packages\pika\adapters\blocking_connection.py", line 451, in _create_connection
raise self._reap_last_connection_workflow_error(error)
pika.exceptions.IncompatibleProtocolError: StreamLostError: ('Transport indicated EOF',)

最佳答案

@Pigeonnn 在 his own comment 中提供了他自己问题的答案对于这篇文章的原始问题:

Actually I've just found a solution. The thing is if you want tolisten to rabbitmq you need to connect through port 5672 - not 15672.Changed ports, forwarded and everything works :)

关于python - 如何连接 Vagrant 主机上的兔子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56262829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com