[英]Python Firebase How to check whether a file exists on firebase storage
[英]Python: Check if Azure queue storage exists
我想获取队列存储并在不存在时创建。 对于大多数类似的场景,我使用的是exists()
方法,但是当我查看 python 文档时( https://learn.microsoft.com/en-us/python/api/azure-storage-queue/azure.storage.queue.queueclient ?view=azure-python ) 我看不到任何可以解决此问题的方法这是我的代码:
def send_to_queue(CONN_STR, queue_name, mess):
service_client = QueueServiceClient.from_connection_string(conn_str=CONN_STR)
queue = service_client.get_queue_client(queue_name)
if not queue.exists():
queue.create_queue()
queue.send_message(mess)
我可以在 if 语句中使用什么来解决这个问题?
您可以改用try
except
。 根据文档create_queue
在存储帐户中创建一个新队列。 如果已存在同名队列,则操作失败并出现ResourceExistsError
。
from azure.core.exceptions import ResourceExistsError
def send_to_queue(CONN_STR, queue_name, mess):
service_client = QueueServiceClient.from_connection_string(conn_str=CONN_STR)
queue = service_client.get_queue_client(queue_name)
try:
queue.create_queue()
except ResourceExistsError:
# Resource exists
pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.