首页 > 解决方案 > 如何对远程计算机上的 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)

有谁知道我该怎么做才能解决这个问题?感谢您的回复

标签: pythonbotstelegramremote-serverrdp

解决方案


C:\\Users\\admin\\Downloads\\bot文件夹而不是文件?

您可以通过添加类似的内容来确认这一点

import os
...
photo_path = 'C:\\Users\\admin\\Downloads\\bot'
assert os.path.isfile(photo_path)
bot.sendPhoto(chat_id, ...
...

推荐阅读