Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,178 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
As a requirement, i want to push the capture mitmdump to azure blob storage. I am using the below code. But getting error as "in script .\log_azureblob.py: ('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000256D5BF62D0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, BlobType
from mitmproxy import http, flowfilter,ctx
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)
if not blob_client.exists():
# if the blob doesn't exist, create it with some initial data
initial_data = b'Initial data for the blob'
blob_client.upload_blob(initial_data)
def start():
# set up the logger
ctx.log.info("BlobLogger started.")
def request(flow):
# get the request data and append it to the blob
request_data = f"{flow.request.method} {flow.request.url} HTTP/1.1\n"
for name, value in flow.request.headers.items():
request_data += f"{name}: {value}\n"
request_data += "\n" # add a blank line between the headers and body
if flow.request.content:
request_data += flow.request.content.decode("utf-8") + "\n"
try:
blob_client.append_block(request_data.encode("utf-8"))
except Exception as e:
ctx.log.error(f"Error appending request data to blob: {e}")
def response(flow):
# get the response data and append it to the blob
response_data = f"HTTP/1.1 {flow.response.status_code} {flow.response.reason}\n"
for name, value in flow.response.headers.items():
response_data += f"{name}: {value}\n"
response_data += "\n" # add a blank line between the headers and body
if flow.response.content:
response_data += flow.response.content.decode("utf-8") + "\n"
try:
blob_client.append_block(response_data.encode("utf-8"))
except Exception as e:
ctx.log.error(f"Error appending response data to blob: {e}")
def done():
# clean up the logger
ctx.log.info("BlobLogger stopped.")
It seems like the issue you're experiencing is related to a proxy that prevents connecting to Azure Blob Storage. Please check and if you require a proxy server add the relevant code
If not please give more details about error code
for example
from azure.core.pipeline.policies import ProxyPolicy
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, BlobType
from mitmproxy import http, flowfilter, ctx
# Add this line to disable proxy:
proxy_policy = ProxyPolicy(proxies={})
# Modify this line to include the proxy_policy:
blob_service_client = BlobServiceClient.from_connection_string(connection_string, policies=[proxy_policy])
blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)
# ... the rest of your code ...