python - 如何对远程计算机上的 Errno 13 Permission Denied 进行故障排除?
问题描述
所以我一直在尝试使用 python 脚本通过电报机器人监控我的 RDP 服务器,但是有一个问题。该程序无权访问屏幕截图输出文件夹,因此机器人无法发送屏幕截图。由于编译器给了我 Errno 13 Permission Denied (点击这里查看错误),我认为问题出在权限上。我尝试使用 Icacls /grant 命令授予我的 RDP 用户对该文件夹的权限,以管理员身份运行编译器,还通过属性手动编辑输出文件夹权限,但似乎没有任何效果。
这是我的代码:
import sys
import time
import telepot
import pyautogui
from telepot.loop import MessageLoop
from tokens import *
class MyBot(telepot.Bot):
def init(self, *args, **kwargs):
super(MyBot, self).init(*args, **kwargs)
self.answerer = telepot.helper.Answerer(self)
self._message_with_inline_keyboard = None
def on_chat_message(self, msg):
content_type, chat_type, chat_id = telepot.glance(msg)
if chat_id in adminId:
if content_type == 'text':
while msg['text'] == '/capture':
bot.sendChatAction(chat_id, 'typing')
bot.sendMessage(chat_id, "Capturing image")
self.capture_img()
bot.sendPhoto(chat_id, photo=open('C:\\Users\\admin\\Downloads\\bot', 'rb'))
time.sleep(3600)
else:
bot.sendMessage(chat_id, "Not admin")
def capture_img(self):
pic = pyautogui.screenshot()
pic.save('C:\\Users\\admin\\Downloads\\bot\\img\\screenshot.png')
return
TOKEN = telegrambot
bot = MyBot(TOKEN)
MessageLoop(bot).run_as_thread()
while 1:
time.sleep(5)
有谁知道我该怎么做才能解决这个问题?感谢您的回复
解决方案
是C:\\Users\\admin\\Downloads\\bot
文件夹而不是文件?
您可以通过添加类似的内容来确认这一点
import os
...
photo_path = 'C:\\Users\\admin\\Downloads\\bot'
assert os.path.isfile(photo_path)
bot.sendPhoto(chat_id, ...
...
推荐阅读
- three.js - 三.js如何绘制坡度(起点和终点高度不同)?
- javascript - 如何理解JavaScript的分析和执行原理
- javascript - 尝试制作自动点击器的 javascript 新手
- math - 如何使用单个参数定义曲线变换?
- python - 为什么Python可以实现a,b = b,a
- css - CSS无限循环问题
- r - 在 R 中使用 tidyverse 在单个 tibble 中汇总分组和未分组的数据
- networking - 当我尝试在网关中 ping “eth1”的 ip 时获取“请求时间”
- python - pyautogui 用于特定窗口的多任务处理
- android-studio - Android Studio:导入 org.tensorflow.Operation 似乎不起作用