Thử nghiệm ML của Azure cung cấp các cách đọc và ghi tệp CSV vào bộ nhớ blob Azure thông qua các mô-đun Reader
và Writer
. Tuy nhiên, tôi cần phải viết một tệp JSON để lưu trữ blob. Vì không có mô-đun để làm như vậy, tôi đang cố gắng làm như vậy từ trong mô-đun Execute Python Script
.Truy cập lưu trữ blog Azure từ bên trong thử nghiệm Azure ML
# 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,
Tuy nhiên, điều này dẫn đến một lỗi: ImportError: No module named azure.storage.blob
này ngụ ý rằng gói azure-storage
Python không được cài đặt trên Azure ML.
Làm cách nào tôi có thể ghi vào bộ nhớ Azure blob từ bên trong thử nghiệm Azure ML?
Dưới đây là thông báo lỗi điền:
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`
Cảm ơn, tất cả mọi người!
CẬP NHẬT: Cảm ơn Dan và Peter vì những ý tưởng bên dưới. Đây là tiến trình tôi đã thực hiện bằng cách sử dụng các đề xuất đó. Tôi đã tạo một môi trường ảo Python 2.7 sạch (trong VS 2005) và đã thực hiện một số pip install azure-storage
để nhận các phụ thuộc vào thư mục gói trang web của mình. Sau đó tôi nén thư mục site-packages và tải lên dưới dạng tệp Zip, theo ghi chú của Dan bên dưới. Sau đó tôi đưa tham chiếu đến thư mục site-packages và nhập thành công các mục cần thiết. Điều này dẫn đến một lỗi thời gian khi viết vào lưu trữ blog.
Đây là mã của tôi:
# 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,
Và đây là các bản ghi lỗi mới:
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
đâu thăm dò hiện tại của tôi đang dẫn đầu được rằng có một sự phụ thuộc vào các requests
Gói Python trong azure-storage
. requests
có lỗi đã biết trong Python 2.7 để gọi các giao thức SSL mới hơn. Không chắc lắm, nhưng bây giờ tôi đang đào bới trong khu vực đó.
CẬP NHẬT 2: Mã này chạy hoàn toàn tốt bên trong sổ ghi chép Python 3 Jupyter. Ngoài ra, nếu tôi mở Vùng chứa Blob để truy cập công khai, tôi có thể trực tiếp ĐỌC từ Vùng chứa thông qua một URL. Ví dụ: df = pd.read_csv("https://mystorageaccount.blob.core.windows.net/upload/test.csv")
dễ dàng tải tệp từ bộ nhớ blob. Tuy nhiên, tôi không thể sử dụng azure.storage.blob.BlobService
để đọc từ cùng một tệp.
UPDATE 3: Dan, trong một bình luận dưới đây, đề nghị tôi thử từ máy tính xách tay Jupyter lưu trữ trên Azure ML. Tôi đã chạy nó từ một máy tính xách tay Jupyter địa phương (xem bản cập nhật 2 ở trên). Tuy nhiên, nó không thành công khi chạy từ một máy tính xách tay Azure ML và lỗi trỏ đến gói requires
một lần nữa. Tôi sẽ cần phải tìm các vấn đề đã biết với gói đó, nhưng từ đọc của tôi, vấn đề đã biết là với urllib3 và chỉ tác động đến Python 2.7 và KHÔNG có bất kỳ phiên bản Python 3.x nào. Và điều này đã được chạy trong một máy tính xách tay Python 3.x. Grrr.
CẬP NHẬT 4: Như Dan lưu ý dưới đây, điều này có thể là một vấn đề với mạng Azure ML, như Execute Python Script
là tương đối mới và chỉ có hỗ trợ kết nối mạng. Tuy nhiên, tôi cũng đã thử nghiệm này trên một webjob dịch vụ ứng dụng Azure, mà là trên một nền tảng Azure hoàn toàn khác nhau. (Nó cũng nằm trên một bản phân phối Python hoàn toàn khác và hỗ trợ cả Python 2.7 và 3.4/5, nhưng chỉ ở 32 bit - ngay cả trên các máy 64 bit.) Mã cũng thất bại, với thông báo InsecurePlatformWarning
.
[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
Dan, tôi đánh giá cao phản hồi. Đó là một phần giới thiệu tuyệt vời trong việc thiết lập mọi thứ với một tệp nén, nhưng chỉ gợi ý cách giải quyết vấn đề cốt lõi khi không thể nhập azure.storage.blob một cách hiệu quả. Tôi đã lấy mã thực tế từ Github và đưa nó vào để tôi có thể tham khảo nó. Điều này thành công cho phép tôi tham khảo azure.storage.blob, tuy nhiên, điều đó là không đủ vì tất cả các yêu cầu đều hết thời gian. Tôi sẽ giải quyết nó nhiều hơn trong một bình luận cho bài viết gốc của tôi. Nhưng tôi thực sự muốn nói lời cảm ơn, Dan. Điều này rất hữu ích, đặc biệt đối với những người có câu hỏi tương tự sau này. –
Tôi không thấy bản cập nhật cho câu hỏi ... Nhưng vùng chứa bạn đang cố tải lên blob có tồn tại không? Mã của bạn sẽ không tạo vùng chứa nếu nó chưa có ở đó. Có thể cần thêm 'blob_service.create_container ('mycontainer')'? Hy vọng điều này có thể giúp đỡ. –
Cảm ơn một lần nữa, Dan. Tôi đã cập nhật câu hỏi và lưu ý các vấn đề rõ ràng hơn. Vùng chứa tồn tại và tôi thậm chí không thể tạo vùng chứa từ Azure ML. Tôi hy vọng bản cập nhật của tôi làm cho nó rõ ràng hơn. Cảm ơn một lần nữa cho công việc của bạn. Tôi yêu Azure và tôi yêu Python. Tôi thực sự muốn chúng tôi có thể Python trên các dịch vụ Azure PaaS và SaaS! –