reifen Sie über ein Azure ML-Experiment auf den Azure-Blogspeicher z

Azure ML-Experimente bieten Möglichkeiten zum Lesen und Schreiben von CSV-Dateien in den Azure-Blob-Speicher über dasReader undWriter Module. Ich muss jedoch eine JSON-Datei für den Blob-Speicher schreiben. Da es kein Modul dafür gibt, versuche ich es aus einem @ herauExecute Python Script module.

# Import the necessary items
from azure.storage.blob import BlobService

def azureml_main(dataframe1 = None, dataframe2 = None):
    account_name = 'mystorageaccount'
    account_key='mykeyhere=='
    json_string='{jsonstring here}'

    blob_service = BlobService(account_name, account_key)

    blob_service.put_block_blob_from_text("upload","out.json",json_string)

    # Return value must be of a sequence of pandas.DataFrame
    return dataframe1,

Dies führt jedoch zu einem Fehler:ImportError: No module named azure.storage.blob

Dies impliziert, dass dasazure-storage Python-Paket ist nicht auf Azure ML installiert.

Wie kann ich aus einem Azure ML-Experiment heraus in den Azure-Blob-Speicher schreiben?

Hier ist die Füllfehlermeldung:

Error 0085: The following error occurred during script evaluation, please view the output log for more information:
---------- Start of error message from Python interpreter ----------
data:text/plain,Caught exception while executing function: Traceback (most recent call last):
  File "C:\server\invokepy.py", line 162, in batch
    mod = import_module(moduleName)
  File "C:\pyhome\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\temp\azuremod.py", line 19, in <module>
    from azure.storage.blob import BlobService
ImportError: No module named azure.storage.blob

---------- End of error message from Python  interpreter  ----------
Start time: UTC 02/06/2016 17:59:47
End time: UTC 02/06/2016 18:00:00`

ielen Dank an all

UPDATE: Danke an Dan und Peter für die Ideen unten. Dies ist der Fortschritt, den ich mit diesen Empfehlungen gemacht habe. Ich habe eine saubere virtuelle Python 2.7-Umgebung (in VS 2005) erstellt und ein @ erstellpip install azure-storage um die Abhängigkeiten in mein Site-Paketverzeichnis zu bekommen. Ich habe dann den Site-Packages-Ordner gezippt und als Zip-Datei hochgeladen, wie in Dans Hinweis unten angegeben. Anschließend habe ich den Verweis auf das Site-Packages-Verzeichnis eingefügt und die erforderlichen Elemente erfolgreich importiert. Dies führte zu einem Timeout-Fehler beim Schreiben in den Blog-Speicher.

Hier ist mein Code:

# Get access to the uploaded Python packages    
import sys
packages = ".\Script Bundle\site-packages"
sys.path.append(packages)

# Import the necessary items from packages referenced above
from azure.storage.blob import BlobService
from azure.storage.queue import QueueService

def azureml_main(dataframe1 = None, dataframe2 = None):
    account_name = 'mystorageaccount'
    account_key='p8kSy3F...elided...3plQ=='

    blob_service = BlobService(account_name, account_key)
    blob_service.put_block_blob_from_text("upload","out.txt","Test to write")

    # All of the following also fail
    #blob_service.create_container('images')
    #blob_service.put_blob("upload","testme.txt","foo","BlockBlob")

    #queue_service = QueueService(account_name, account_key)
    #queue_service.create_queue('taskqueue')

    # Return value must be of a sequence of pandas.DataFrame
    return dataframe1,

Und hier ist das neue Fehlerprotokoll:

Error 0085: The following error occurred during script evaluation, please view the output log for more information:
---------- Start of error message from Python interpreter ----------
data:text/plain,C:\pyhome\lib\site-packages\requests\packages\urllib3\util\ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Caught exception while executing function: Traceback (most recent call last):   
  File "C:\server\invokepy.py", line 169, in batch
    odfs = mod.azureml_main(*idfs)
  File "C:\temp\azuremod.py", line 44, in azureml_main
    blob_service.put_blob("upload","testme.txt","foo","BlockBlob")
  File ".\Script Bundle\site-packages\azure\storage\blob\blobservice.py", line 883, in put_blob
    self._perform_request(request)
  File ".\Script Bundle\site-packages\azure\storage\storageclient.py", line 171, in _perform_request
    resp = self._filter(request)
  File ".\Script Bundle\site-packages\azure\storage\storageclient.py", line 160, in _perform_request_worker
    return self._httpclient.perform_request(request)
  File ".\Script Bundle\site-packages\azure\storage\_http\httpclient.py", line 181, in perform_request
    self.send_request_body(connection, request.body)
  File ".\Script Bundle\site-packages\azure\storage\_http\httpclient.py", line 143, in send_request_body
    connection.send(request_body)
  File ".\Script Bundle\site-packages\azure\storage\_http\requestsclient.py", line 81, in send
    self.response = self.session.request(self.method, self.uri, data=request_body, headers=self.headers, timeout=self.timeout)
  File "C:\pyhome\lib\site-packages\requests\sessions.py", line 464, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\pyhome\lib\site-packages\requests\sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "C:\pyhome\lib\site-packages\requests\adapters.py", line 431, in send
    raise SSLError(e, request=request)
SSLError: The write operation timed out

---------- End of error message from Python  interpreter  ----------
Start time: UTC 02/10/2016 15:33:00
End time: UTC 02/10/2016 15:34:18

Wo meine aktuelle Erkundung hinführt, ist, dass es eine Abhängigkeit vom @ gibrequests Python-Paket inazure-storage. requests hat einen bekannten Fehler in Python 2.7 beim Aufrufen neuerer SSL-Protokolle. Ich bin mir nicht sicher, aber ich grabe mich gerade in diesem Bereich um.

UPDATE 2: Dieser Code läuft in einem Python 3 Jupyter-Notebook einwandfrei. Wenn ich den Blob-Container für den öffentlichen Zugriff freigebe, kann ich ihn außerdem über eine URL direkt aus dem Container LESEN. Zum Beispiel:df = pd.read_csv("https://mystorageaccount.blob.core.windows.net/upload/test.csv") lädt die Datei einfach aus dem Blob-Speicher. Ich kann jedoch das @ nicht verwendazure.storage.blob.BlobService, um aus derselben Datei zu lesen.

UPDATE 3: Dan schlug in einem Kommentar unten vor, ich versuche es mit den Jupyter-Notizbüchernhosted auf Azure ML. Ich hatte es von einem lokalen Jupyter-Notebook aus ausgeführt (siehe Update 2 oben).Jedoc schlägt fehl, wenn es von einem Azure ML-Notizbuch ausgeführt wird, und die Fehler verweisen auf dasrequires Paket wieder. Ich muss die bekannten Probleme mit diesem Paket finden, aber nach meiner Lektüre liegt das bekannte Problem bei urllib3 und betrifft nur Python 2.7 und KEINE Python 3.x-Versionen. Und dies wurde in einem Python 3.x-Notizbuch ausgeführt. Grrr.

UPDATE 4: Wie Dan unten feststellt, kann dies ein Problem beim Azure ML-Netzwerk sein, daExecute Python Script ist relativ neu und hat gerade Netzwerkunterstützung erhalten. Ich habe dies jedoch auch auf einem Azure App Service-Webjob getestet, der sich auf einer völlig anderen Azure-Plattform befindet. (Es befindet sich ebenfalls in einer völlig anderen Python-Distribution und unterstützt sowohl Python 2.7 als auch 3.4 / 5, jedoch nur 32-Bit-Versionen - auch auf 64-Bit-Computern.) Der dortige Code schlägt ebenfalls fehl, mit einemInsecurePlatformWarning Botschaft

[02/08/2016 15:53:54 > b40783: SYS INFO] Run script 'ListenToQueue.py' with script host - 'PythonScriptHost'
[02/08/2016 15:53:54 > b40783: SYS INFO] Status changed to Running
[02/08/2016 15:54:09 > b40783: INFO] test.csv
[02/08/2016 15:54:09 >, b40783: ERR ] D:\home\site\wwwroot\env\Lib\site-packages\requests\packages\urllib3\util\ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
[02/08/2016 15:54:09 > b40783: ERR ]   SNIMissingWarning
[02/08/2016 15:54:09 > b40783: ERR ] D:\home\site\wwwroot\env\Lib\site-packages\requests\packages\urllib3\util\ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
[02/08/2016 15:54:09 > b40783: ERR ]   InsecurePlatformWarning
[02/08/2016 15:54:09 > b40783: ERR ] D:\home\site\wwwroot\env\Lib\site-packages\requests\packages\urllib3\util\ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
[02/08/2016 15:54:09 > b40783: ERR ]   InsecurePlatformWarning

Antworten auf die Frage(6)

Ihre Antwort auf die Frage