python-couchdb:如何检查数据库是否已经存在(How to check if database already exists)
我正在编写一个小型的Python程序,将一些文件加载到couchdb中。 检查具有特定名称的数据库是否已经存在是非常方便的,因此我可以创建一个新数据库或打开现有数据库。 我想做的是这样的:
import couchdb def connect(url, dbName): server = couchdb.Server(url) if dbName exists: # how do I do this? return server[dbName] else: return server.create(dbName)
我知道一个尝试 - 除了块会做的伎俩,但没有一个更优雅的方式?
I am writing a small Python program that loads some documents into couchdb. It would be very convenient to check whether a database with a certain name already exists, so I can either create a new one or open the existing one. What I want to do is something like this:
import couchdb def connect(url, dbName): server = couchdb.Server(url) if dbName exists: # how do I do this? return server[dbName] else: return server.create(dbName)
I know a try-except block would do the trick, but isn't there a more elegant way?
原文:https://stackoverflow.com/questions/35465360
最满意答案
生长激素正面临与您同样的事件,并且有意见,我们可以发现这种情况目前不会改变。
不过,我们可以从评论中获得一些提示:
最终,你不能从客户端隐藏秘密/令牌。
- 如果你想从URL中删除它,你可以自己托管JS控件。
- 如果你想从页面源代码中移除它,你可以在cookie中传递值>并在你的网页中用JS读取它。
但是,在所有情况下,该值都将在内存中提供。
我认为你可以自己建立另一个简单的网站,作为iframe和yout bot应用程序的桥梁。 您可以限制您的用户在本网站的会话中是否唯一。 此外,您还可以在实例化Bot WebChat之前验证您的用户。
There is an issue on GH which is facing the same event with you, and with the comments, we can found that this situation will not be changed currently.
However, we can get some hints from the comment:
Ultimately, you can't hide the secret/token from clients.
- If you want to remove it from the URL, you can host the JS control on your own.
- If you want to remove it from page source, you can pass the value in a cookie >and read it in JS in your webpage.
However, in all cases, the value will be available in memory.
I think you can build another simple web site yourself as the bridge from the iframe and yout bot application. You can restrict your user whether is unique in this website's session. And also you can verify your user before instantiate the Bot WebChat.
相关问答
更多-
请使用new来创建直接连接实例: var botConnection = new BotChat.DirectLine({ secret:
}); Please use new to create the directline connection instance: var botConnection = new BotChat.DirectLine({ secret: }); -
模拟器上的最新主机正在打破访问令牌请求。 您需要签出提交4923221才能使其正常工作。 要使用帖子请求直接获取访问令牌:帖子网址是https://login.microsoftonline.com/common/oauth2/v2.0/token ,范围是https://graph.microsoft.com/。 default其余部分应如前所述 The latest master on Emulator is breaking the access token request. You need to ...
-
错误(HTTP状态码502)表示机器人返回错误或请求超时。 您可以转到机器人的通道刀片 ,然后单击受影响通道的“问题”链接以检查有关错误的信息,或使用应用程序见解跟踪错误详细信息。 此外,如果可能的话,您可以在Visual Studio中使用Bot Builder SDK创建一个新的简单机器人应用程序,并升级项目的Bot Builder SDK,然后使用以下步骤和图表将其部署到相应的Azure应用程序服务,并检查新的机器人应用程序是否可以工作与机器人服务。 创建它之后,将在您的资源组中创建两个资源: Web ...
-
我不是React的专家,但我发现在React中,我们只能通过其状态更新输入值。 通过源代码 ,似乎有一个名为onChangeText()的入口函数。 所以,请尝试下面的代码片段来更新输入值: componentDidMount(){ console.log(this.chat); this.chat.shellRef.props.onChangeText('testMsg'); } I am not expert in React, but I found that i ...
-
您可以通过搜索Github上的网聊资料库快速找到您要查找的内容。 如果你搜索incoming你会去这些线 ,这可能是你的需要有趣的: private handleIncomingActivity(activity: Activity) { let state = this.store.getState(); switch (activity.type) { case "message": this.store.dispatch
... -
你有没有检查过你的机器人LuisRecognizers的初始化并将它们相互比较? 它们很可能在代码上稍有差异, BotBuilder-Sample / Node / intelligence-LUIS示例仅使用第27行的botbuilder的LuisRecognizer 。 var recognizer = new builder.LuisRecognizer(process.env.LUIS_MODEL_URL); // Line 27 bot.recognizer(recognizer); bot.d ...
-
使用.NetCore 2的MS Botframework不使用仿真器进行身份验证(MS Botframework using .NetCore 2 not authenticating using Emulator)[2023-05-28]
在这个时候.NET核心2.0不支持。 我们目前正在开发一款支持正在测试的.NET核心2.0的版本。 如果有样本和任何可用的文档资源,我会更新这篇文章。 At this time .NET core 2.0 is not supported. We are currently working on a release to support .NET core 2.0 it is in testing right now. I will update this post when it is with samp ... -
在microsoft bot框架上获取403禁止使用网络聊天(Getting 403 Forbidden with webchat on microsoft bot framework)[2023-09-17]
正如评论中所讨论的,您尝试使用的密钥对应于自定义语音服务API ,您尝试运行的示例需要 Bing Speech API密钥。 Bing Speech是提供语音到文本功能的服务。 As discussed in the comments, the key you are trying to use corresponds to Custom Speech Service API, and the sample you are trying to run needs a Bing Speech API key. ... -
对此有几件事。 首先, imBack主要代表IM返回,或即时消息。 它会将回复发送给对话。 你想要postBack ,它会隐藏响应,但请记住,对于某些频道, postBack会映射到imBack ,所以你必须做一些调查。 对于Bot Emulator, postBack将隐藏响应。 第二件事,如果您在机器人运行时观察控制台,您将看到机器人将尝试在imBack方法中路由到该值 。 您需要通过对话框或意图捕获它。 这是一个很小的,效率很低的例子: intents.matches(/^suggest/i, [(s ...
-
MS BotFramework WebChat URL中的临时令牌问题(MS BotFramework Temporary token issue in WebChat URL)[2022-12-08]
生长激素正面临与您同样的事件,并且有意见,我们可以发现这种情况目前不会改变。 不过,我们可以从评论中获得一些提示: 最终,你不能从客户端隐藏秘密/令牌。 如果你想从URL中删除它,你可以自己托管JS控件。 如果你想从页面源代码中移除它,你可以在cookie中传递值>并在你的网页中用JS读取它。 但是,在所有情况下,该值都将在内存中提供。 我认为你可以自己建立另一个简单的网站,作为iframe和yout bot应用程序的桥梁。 您可以限制您的用户在本网站的会话中是否唯一。 此外,您还可以在实例化Bot Web ...