Import MongoDB data to Azure ML Studio from Python Script

丶灬走出姿态 提交于 2021-01-29 08:17:50

问题


Currently in Azure ML's while executing python script, with following code. (Python 2.7.11) In which results obtained from the mongoDB are trying to return in DataFrame using pyMongo.

I got an error like ::

"C:\pyhome\lib\site-packages\pymongo\topology.py", line 97, in select_servers
        self._error_message(selector))
    ServerSelectionTimeoutError: ... ('The write operation timed out',)

Please let me know if you know about the cause of the error and what to improve.

My Source code :

import pymongo as m
import pandas as pd

def azureml_main(dataframe1 = None, dataframe2 = None):

uri = "mongodb://xxxxx:yyyyyyyyyyyyyyy@zzz.mongodb.net:xxxxx/?ssl=true&replicaSet=globaldb"
client = m.MongoClient(uri,connect=False)
db = client['dbName']
coll = db['colectionName']
cursor = coll.find()
df = pd.DataFrame(list(cursor))
return df,

Error Details:

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\55a174d8dc584942908423ebc0bac110.py", line 32, in azureml_main
    result =  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))
ServerSelectionTimeoutError: xxxxx-xxx.mongodb.net:xxxxx: ('The write operation timed out',)
Process returned with non-zero exit code 1

回答1:


As I known, there are a limitation of Execute Python Scripts which will cause this issue, please refer to the section Limitations to know it, as below.

Limitations

The Execute Python Script currently has the following limitations:

  1. Sandboxed execution. The Python runtime is currently sandboxed and, as a result, does not allow access to the network or to the local file system in a persistent manner. All files saved locally are isolated and deleted once the module finishes. The Python code cannot access most directories on the machine it runs on, the exception being the current directory and its subdirectories.

Due to the reason above, you can not directly import the data from Azure Cosmos DB online via pymongo driver in Execute Python Script module. But you can use Import Data module with the connection and parameters information of your Azure Cosmos DB and connect its output to the input of Execute Python Script to get the data, as the figure below.

For more information to import data online, please refer to the section Import from online data sources of the offical document Import your training data into Azure Machine Learning Studio from various data sources.



来源:https://stackoverflow.com/questions/54502828/import-mongodb-data-to-azure-ml-studio-from-python-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!