【问题标题】:Import data from MongoDB atlas to Azure Machinelearning将数据从 MongoDB atlas 导入 Azure 机器学习
【发布时间】:2019-09-20 10:08:03
【问题描述】:

我正在尝试使用 python 脚本将数据从 MongoDB 导入 Azure 机器学习。我使用以下脚本:

import pymongo as pymongo
import pandas as pd

def azureml_main(dataframe1 = None, dataframe2 = None):
    client = pymongo.MongoClient("SERVER:USERNAME:PASSWORD")
    db = client['DATABASE']
    coll = db['COLLECTION']
    cursor = coll.find().limit(10)
    df = pd.DataFrame(list(cursor))
    return df,

这给了我以下错误:

Error 0085: The following error occurred during script evaluation, please view the output log for more information:
---------- Start of error message from Python interpreter ----------
Caught exception while executing function: Traceback (most recent call last):
  File "C:\server\invokepy.py", line 199, in batch
    odfs = mod.azureml_main(*idfs)
  File "C:\temp\416f67ae321a4f7b9a2d5eda63aa127c.py", line 23, in azureml_main
    df = pd.DataFrame(list(cursor))
  File "C:\pyhome\lib\site-packages\pymongo\cursor.py", line 977, in next
    if len(self.__data) or self._refresh():
  File "C:\pyhome\lib\site-packages\pymongo\cursor.py", line 902, in _refresh
    self.__read_preference))
  File "C:\pyhome\lib\site-packages\pymongo\cursor.py", line 813, in __send_message
    **kwargs)
  File "C:\pyhome\lib\site-packages\pymongo\mongo_client.py", line 728, in _send_message_with_response
    server = topology.select_server(selector)
  File "C:\pyhome\lib\site-packages\pymongo\topology.py", line 121, in select_server
    address))
  File "C:\pyhome\lib\site-packages\pymongo\topology.py", line 97, in select_servers
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: SERVERNAME:XXXXX:[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond,SERVERNAME:XXXXX: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond,SERVERNAME:XXXXX: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Process returned with non-zero exit code 1

这是由于没有将任何 IP 地址列入白名单造成的吗?我找不到任何有关 Azure ML 产生何种 IP 的信息。这个问题有解决方法吗?

【问题讨论】:

    标签: azure-machine-learning-studio mongodb-atlas


    【解决方案1】:

    该错误与任何 IP 白名单无关;它与无法连接到您的 mongo 数据库有关。检查您的连接字符串,并且您的服务器正在运行。连接字符串应该类似于

    mongodb://username:password@server:27017/yourdatabase?authSource=admin
    

    首先使用您选择的命令提示符/shell检查它是否工作

    mongo mongodb://username:password@server:27017/yourdatabase?authSource=admin
    

    然后将您的 python 连接更改为:

    client = pymongo.MongoClient("<working connection string>")
    

    【讨论】:

    • 我尝试在 Visual Studio 代码中使用相同的脚本,并且能够毫无问题地获取数据。我什至用旧python的连接字符串来尝试它,这也很好用。但是当我在 Azure 机器学习工作室运行它时,我仍然卡在超时
    • 好的,我现在更好地理解了您对白名单的评论。也许某些东西阻止了 27017,因为它不是“标准”端口;您可能需要在某处启用某些东西以允许该访问;我对 Azure ML 一无所知,所以恐怕在这方面无能为力。你测试过你的 mongodb 是否可以从外部访问?
    • 不确定你是否找到了答案,但也许这可以解释问题:stackoverflow.com/questions/54502828/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 2020-05-03
    • 1970-01-01
    • 2016-11-03
    • 2015-03-15
    • 1970-01-01
    相关资源
    最近更新 更多