每次截图后关闭图片后出来这个

问题:

Traceback (most recent call last):
  File "E:\An3\lib\site-packages\psutil\_pswindows.py", line 716, in wrapper
    return fun(self, *args, **kwargs)
  File "E:\An3\lib\site-packages\psutil\_pswindows.py", line 873, in kill
    return cext.proc_kill(self.pid)
PermissionError: [WinError 5] 拒绝访问。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "京东.py", line 154, in <module>
    task2()
  File "<string>", line 2, in task2
  File "E:\An3\lib\site-packages\pony\orm\core.py", line 528, in new_func
    result = func(*args, **kwargs)
  File "京东.py", line 81, in task2
    see_invoice(driver,html,i)
  File "京东.py", line 118, in see_invoice
    get_product_screenshot(html2)
  File "京东.py", line 145, in get_product_screenshot
    picture_kill(process)
  File "京东.py", line 131, in picture_kill
    proc.kill()
  File "E:\An3\lib\site-packages\psutil\__init__.py", line 392, in wrapper
    return fun(self, *args, **kwargs)
  File "E:\An3\lib\site-packages\psutil\__init__.py", line 1368, in kill
    self._proc.kill()
  File "E:\An3\lib\site-packages\psutil\_pswindows.py", line 718, in wrapper
    raise convert_oserror(err, pid=self.pid, name=self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=13940)

代码:

def get_process_list():
    '''获取当前进程'''
    process_list = []
    for proc in psutil.process_iter():
        process_list.append(proc)
    return process_list

def picture_kill(process_list):
    '''和之前的进程比较,若有新进程则关闭'''
    for proc in psutil.process_iter():
        if not proc in process_list:
            proc.kill()

def get_product_screenshot(html):
    '''截图并保存图片'''
    process = get_process_list()
    img = ImageGrab.grab((445,195,1467,872))
    img.show()
    number = get_order_number(html)
    path = 'E:\python\京东'
    path1 = path + '\\' + number
    path2 = path1 + '\\' + number + '.jpg'
    if not os.path.exists(path):
        os.makedirs(path1)
    img.save(path2)
    picture_kill(process)

1个回答

PermissionError: [WinError 5] 拒绝访问。
关闭进程的时候提是没有权限,看看是不是进程已经不存在了或者权限不够
用os.exec("taskkill 你的进程")试试看

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问