I've created an Azure Function - HTTP Trigger in VS Code but I face an error related to SSL. As a summary, I would like the function to read a csv file from one blob storage container ( works ), and then generate another .txt file and upload it to a different blob storage container ( this part seems to generate the ssl error ). Can't seem to find the root of the problem, does somebody has an idea on how to approach it?
Python Code:
import pandas as pd
from datetime import datetime, timedelta
import logging
import azure.functions as func
from azure.storage.blob import BlobServiceClient, generate_container_sas, ContainerSasPermissions, generate_blob_sas, BlobSasPermissions, ContainerClient
from azure.core.exceptions import HttpResponseError, ResourceExistsError
import time
import os
import uuid
# using generate_container_sas
def get_img_url_with_container_sas_token(account_name,container_name,account_key):
container_sas_token = generate_container_sas(
account_name=account_name,
container_name=container_name,
account_key=account_key,
permission=ContainerSasPermissions(read=True),
expiry=datetime.utcnow() + timedelta(hours=1)
)
return container_sas_token
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = "xxxxx"
key = "xxxxx"
raw_container = "raw"
blob_name = 'employee.csv'
gen_token = get_img_url_with_container_sas_token(name,raw_container,key)
INPUTSTORAGEACCOUNTURLSAS = f"https://{name}.blob.core.windows.net/{raw_container}/{blob_name}?{gen_token}"
#df = pd.read_csv(INPUTSTORAGEACCOUNTURLSAS,delimiter=',')
connect_str ='xxxxx'
# Create a file in local data directory to upload and download
local_file_name = "quickstart" + str(uuid.uuid4()) + ".txt"
upload_file_path = "xxxxx" + local_file_name
# Write text to the file
file = open(upload_file_path, 'w')
file.write("Hello, World!")
file.close()
container_name = 'proccessed'
# Create a blob client using the local file name as the name for the blob
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
blob_client = blob_service_client.get_blob_client(container=container_name, blob=local_file_name)
print("\nUploading to Azure Storage as blob:\n\t" + local_file_name)
# Upload the created file
with open(upload_file_path, "rb") as data:
#print(data)
blob_client.upload_blob(data)
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
Error resulted:
Executed 'Functions.ecr_xml_to_dl' (Failed, Id=7190b60c-4f2c-4c14-ad3c-b76735405953, Duration=96214ms)
[2020-12-07T12:27:42.443Z] System.Private.CoreLib: Exception while executing function: Functions.ecr_xml_to_dl. System.Private.CoreLib: Result: Failure
Exception: ServiceRequestError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:852)
Stack: File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.6/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 349, in _handle__invocation_request
self.__run_sync_func, invocation_id, fi.func, args)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.6/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 511, in __run_sync_func
return func(**params)
File "C:\Users\USER\Documents\Work\Coding\Azure_Test_Function\ecr_xml_to_dl\__init__.py", line 58, in main
blob_client.upload_blob(data)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\tracing\decorator.py", line 83, in wrapper_use_tracer
return func(*args, **kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\storage\blob\_blob_client.py", line 539, in upload_blob
return upload_block_blob(**options)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\storage\blob\_upload_helpers.py", line 106, in upload_block_blob
**kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\storage\blob\_generated\operations\_block_blob_operations.py", line 217, in upload
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\_base.py", line 211, in run
return first_node.send(pipeline_request) # type: ignore
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
response = self.next.send(request)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
response = self.next.send(request)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
response = self.next.send(request)
[Previous line repeated 2 more times]
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\policies\_redirect.py", line 157, in send
response = self.next.send(request)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
response = self.next.send(request)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\storage\blob\_shared\policies.py", line 515, in send
raise err
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\storage\blob\_shared\policies.py", line 489, in send
response = self.next.send(request)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
response = self.next.send(request)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
response = self.next.send(request)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
response = self.next.send(request)
[Previous line repeated 1 more time]
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\storage\blob\_shared\policies.py", line 290, in send
response = self.next.send(request)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
response = self.next.send(request)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
response = self.next.send(request)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\_base.py", line 103, in send
self._sender.send(request.http_request, **request.context.options),
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\storage\blob\_shared\base_client.py", line 319, in send
return self._transport.send(request, **kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\pipeline\transport\_requests_basic.py", line 285, in send
raise error