从一个 VM 连接到另一个时,urlopen 错误 [Errno 111] python 中的连接被拒绝
urlopen error [Errno 111] Connection refused in python when connecting from one VM to another
我正在测试 python 中的一个脚本,该脚本将一些任意值保存在 mongo 数据库中。此脚本在一个虚拟机上运行,mongo 数据库在另一台虚拟机上运行。在本地测试时(没有将我的代码部署到虚拟机)一切正常,但自从我开始在虚拟机上测试后,我收到此错误:
File "/usr/lib/python2.7/urllib2.py", line 1169, in do_open raise URLError(err)
urllib2.URLError: <urlopen error [Errno 111] Connection refused>
我尝试使用以下代码片段连接到 mongo 虚拟机:
import os, pyjsonrpc
storeClient = pyjsonrpc.HttpClient(
url = os.getenv("URL_DATASTORE", "http://localhost:8081/jsonrpc/"),
username = "",
password = "")
我可以从我的脚本 VM ping 我的 mongodb VM 没有问题,但是当我尝试通过 storeClient 连接时,我收到 urllib2
错误。有什么想法吗?
您正在尝试访问错误的服务器:
url = os.getenv("URL_DATASTORE", "http://localhost:8081/jsonrpc/"),
# ^^^^^^^^^
你是 运行 它在不同的虚拟机上,而不是本地主机。
我正在测试 python 中的一个脚本,该脚本将一些任意值保存在 mongo 数据库中。此脚本在一个虚拟机上运行,mongo 数据库在另一台虚拟机上运行。在本地测试时(没有将我的代码部署到虚拟机)一切正常,但自从我开始在虚拟机上测试后,我收到此错误:
File "/usr/lib/python2.7/urllib2.py", line 1169, in do_open raise URLError(err)
urllib2.URLError: <urlopen error [Errno 111] Connection refused>
我尝试使用以下代码片段连接到 mongo 虚拟机:
import os, pyjsonrpc
storeClient = pyjsonrpc.HttpClient(
url = os.getenv("URL_DATASTORE", "http://localhost:8081/jsonrpc/"),
username = "",
password = "")
我可以从我的脚本 VM ping 我的 mongodb VM 没有问题,但是当我尝试通过 storeClient 连接时,我收到 urllib2
错误。有什么想法吗?
您正在尝试访问错误的服务器:
url = os.getenv("URL_DATASTORE", "http://localhost:8081/jsonrpc/"),
# ^^^^^^^^^
你是 运行 它在不同的虚拟机上,而不是本地主机。