- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在玩 Windows Server 2012 r2。我在服务器上有一些文件。我有一个单独的服务帐户,可以读取这些文件。我想做的是使用 python 通过网络共享访问文件(欢迎任何其他建议),但只能通过服务帐户访问。
PS:我不能使用 RDP。
最佳答案
此任务的基础 WINAPI 是 [MS.Docs]: WNetAddConnection2W function 的一部分家庭。
[GitHub]: mhammond/pywin32 - Python for Windows (pywin32) Extensions wrapper 是 [ActiveState]: Module win32wnet (这不是官方文档(目前我找不到任何文档)- 我不知道 URL 的有效期有多长,但这是我能找到的最好的)。URL p>
我准备了一个简单的例子。
code00.py:
#!/usr/bin/env python3
import sys
import os
import pywintypes
import win32wnet
CONNECT_INTERACTIVE = 0x00000008
HOST_NAME = "192.168.1.3"
SHARE_NAME = "Work"
SHARE_FULL_NAME = os.path.sep * 2 + os.path.sep.join((HOST_NAME, SHARE_NAME))
SHARE_USER = "cfati"
SHARE_PWD = "********"
def main():
net_resource = win32wnet.NETRESOURCE()
net_resource.lpRemoteName = SHARE_FULL_NAME
flags = 0
#flags |= CONNECT_INTERACTIVE
print("Trying to create connection to: {:s}".format(SHARE_FULL_NAME))
try:
win32wnet.WNetAddConnection2(net_resource, SHARE_PWD, SHARE_USER, flags)
except pywintypes.error as e:
print(e)
else:
print("Success!")
if __name__ == "__main__":
print("Python {:s} on {:s}\n".format(sys.version, sys.platform))
main()
注意事项:
这是最简单的功能(相当于您的命令),但是该功能可以做更多的事情:
我想指出一件事。如果你:
flags |= CONNECT_INTERACTIVE
行然后会弹出一个凭证对话框
输出:
(py35x64_test) e:\Work\Dev\StackOverflow\q050602112>net use
New connections will be remembered.
There are no entries in the list.
(py35x64_test) e:\Work\Dev\StackOverflow\q050602112>"e:\Work\Dev\VEnvs\py35x64_test\Scripts\python.exe" code00.py
Python 3.5.4 (v3.5.4:3f56838, Aug 8 2017, 02:17:05) [MSC v.1900 64 bit (AMD64)] on win32
Trying to create connection to: \\192.168.1.3\Work
Success!
(py35x64_test) e:\Work\Dev\StackOverflow\q050602112>net use
New connections will be remembered.
Status Local Remote Network
-------------------------------------------------------------------------------
OK \\192.168.1.3\Work Microsoft Windows Network
The command completed successfully.
(py35x64_test) e:\Work\Dev\StackOverflow\q050602112>net use * /delete /y
You have these remote connections:
\\192.168.1.3\Work
Continuing will cancel the connections.
The command completed successfully.
(py35x64_test) e:\Work\Dev\StackOverflow\q050602112>net use
New connections will be remembered.
There are no entries in the list.
关于python - 使用服务帐户通过 python 访问文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50602112/
2 个不同的租户(租户 A 中的订阅 A 和租户 B 中的订阅 B) 我们在 Azure 云中有一个订阅,并且我们已经设置了 Azure Keyvault。我们可以在那里创建 key 并使用其中一个
账户-B: 在具有 4 个安全组的 vpc(vpc-B) 中包含 RDS。 我为账户 A 创建了承担角色 具有以下政策: [![在此处输入图像描述][1]][1] [![在此处输入图像描述][2]][
我想问一下如果我使用 Google Apps 帐户而不是 Google 帐户 users.create_login_url() 函数来生成登录页面。 Google 会自动要求我使用 Google 帐户
我正在使用帐户 (accounts-hithub)。现在工作正常,但现在我想更新当前用户。 我尝试过类似的事情 Accounts.update({_id: Meteor.user()._id}, {.
ngrok 的配置文件只允许一个 authtoken 行,您作为用户可用的所有资源(例如,保留的主机名)都基于关联的帐户使用授权 token 。 如果您有多个 ngrok 帐户——例如,一个专业(工作
作为 Coursera 数据科学家类(class)设置的一部分,我错误地将目录 test-repo 链接到错误的帐户。所以,在声明中: git remote add origin https://gi
我想使用 Keycloak 设置 Google 联盟,但仅限于我公司的授权用户。 设置 Google 联盟允许任何 Google 帐户登录。 我查看了 Keycloak 上的身份验证流程,但一直找不到
我正在使用 web3 制作自己的桌面 BSC 钱包。目前我正在使用 private_key = "private key" account = w3.eth.account.privateKeyToA
我们的 Subversion 存储库和 Phabricator 安装有不同的身份验证系统。 但似乎 Phabricator 假定提交作者和 Phabricator 帐户将相同。文档中没有提到提交作者如
我正在使用 codio.com 。从那里我使用 ubuntu 终端登录 Heroku,但它给了我以下错误。我已阅读帮助 page还 。它说使用 MFA 您必须使用浏览器进行登录。但问题是浏览器没有从
我正在尝试第一次发布我的应用程序。如果我没记错的话,为了把admob 广告放到我的应用程序中,我应该有一个admob 帐户。 我的问题是我是否需要使用与打开 Play 商店开发者帐户相同的 gmail
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 3年前关闭。 Improve thi
OS: Ubuntu 18.04 Server Docker 18.3 CE 我使用 PuTTY SSH session 从我的 Windows 10 笔记本电脑登录到服务器。 我的本地 Window
在 Heroku CLI(我使用 WSL/Ubuntu)中,我想查看我当前登录的是哪个 Heroku 帐户。 命令 heroku login开始一个新的登录 session ,但我想知道哪个帐户当前处
除了 [sa] 用户,我在 sysadmin 中没有用户 不幸的是,我以 [sa] 用户身份登录并禁用了它 那么我无法启用它,我该怎么做才能再次启用它? 最佳答案 您必须使用 sqlcmd.exe与
我想找到所有具有索引或已注册身份的 polkadot 帐户;类似于 https://polkascan.io/polkadot/account/identities和 https://polkasca
我想从我的服务器应用程序访问类记录。 我创建了一个服务帐户,但无法从我的 Google 帐户创建的教室中获取记录。 我如何获得访问权限?谢谢 最佳答案 创建服务帐户是不够的。您还必须执行域范围的委派并
我有相同的超链接: HyperLink skype = new HyperLink(); skype.NavigateUrl = "skype:username?call"; 当用户按下它时,他重定向
我和这里的一些人正在创业。我们目前正在使用 Google OpenID API 来管理注册和登录我们的应用程序,但我们希望迁移到更简单的用户注册模型。为此,我们需要知道是否有办法检测电子邮件(不是 g
尝试访问我的 sitemap.xml 时,我收到此错误: 'Account' object has no attribute 'get_absolute_url' on line 112. 109.
我是一名优秀的程序员,十分优秀!