pydoll icon indicating copy to clipboard operation
pydoll copied to clipboard

PermissionError

Open mauroapo opened this issue 8 months ago • 2 comments

I'm getting this error after accesing any page. It loads up but causes this issue after a while of executing.

Traceback (most recent call last): File "C:\Users\Acer\AppData\Local\Programs\Python\Python312\Lib\shutil.py", line 633, in _rmtree_unsafe os.unlink(fullname) PermissionError: [WinError 5] Access is denied: 'C:\Users\Acer\AppData\Local\Temp\tmptawzx8xr\BrowserMetrics\BrowserMetrics-67CF99F5-1758.pma'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\Acer\AppData\Local\Programs\Python\Python312\Lib\weakref.py", line 666, in _exitfunc f() File "C:\Users\Acer\AppData\Local\Programs\Python\Python312\Lib\weakref.py", line 590, in call return info.func(*info.args, **(info.kwargs or {})) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Acer\AppData\Local\Programs\Python\Python312\Lib\tempfile.py", line 935, in _cleanup cls._rmtree(name, ignore_errors=ignore_errors) File "C:\Users\Acer\AppData\Local\Programs\Python\Python312\Lib\tempfile.py", line 930, in _rmtree _shutil.rmtree(name, onexc=onexc) File "C:\Users\Acer\AppData\Local\Programs\Python\Python312\Lib\shutil.py", line 781, in rmtree return _rmtree_unsafe(path, onexc) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Acer\AppData\Local\Programs\Python\Python312\Lib\shutil.py", line 635, in _rmtree_unsafe onexc(os.unlink, fullname, err) File "C:\Users\Acer\AppData\Local\Programs\Python\Python312\Lib\tempfile.py", line 905, in onexc _os.unlink(path) PermissionError: [WinError 5] Access is denied: 'C:\Users\Acer\AppData\Local\Temp\tmptawzx8xr\BrowserMetrics\BrowserMetrics-67CF99F5-1758.pma'`

mauroapo avatar Mar 11 '25 02:03 mauroapo

+1

chenrgSix avatar Mar 11 '25 03:03 chenrgSix

Hi @mauroapo! This error occurs when exiting the context manager, but you can continue your code without any issues. After loading the page, you just need to declare more commands. We also have an open PR from @Nabeelshar to fix this bug.

thalissonvs avatar Mar 11 '25 11:03 thalissonvs

I'm facing this issue on context manager exit in the latest version (2.3.1, Windows). Everything works fine, except that the following error is thrown when the script ends.

Traceback (most recent call last):
  File "C:\Users\main.py", line 37, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "C:\Program Files\Python313\Lib\asyncio\runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "C:\Program Files\Python313\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\Program Files\Python313\Lib\asyncio\base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "C:\Users\scraper.py", line 23, in retrieve_ads
    async with Chrome(options=options) as browser:
               ~~~~~~^^^^^^^^^^^^^^^^^
  File "C:\Users\jay\AppData\Roaming\Python\Python313\site-packages\pydoll\browser\chromium\base.py", line 92, in __aexit__
    await self.stop()
  File "C:\Users\jay\AppData\Roaming\Python\Python313\site-packages\pydoll\browser\chromium\base.py", line 145, in stop
    self._temp_directory_manager.cleanup()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\jay\AppData\Roaming\Python\Python313\site-packages\pydoll\browser\managers\temp_dir_manager.py", line 96, in cleanup
    shutil.rmtree(temp_dir.name, onerror=self.handle_cleanup_error)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python313\Lib\shutil.py", line 790, in rmtree
    return _rmtree_unsafe(path, onexc)
  File "C:\Program Files\Python313\Lib\shutil.py", line 629, in _rmtree_unsafe
    onexc(os.unlink, fullname, err)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python313\Lib\shutil.py", line 754, in onexc
    return onerror(func, path, exc_info)
  File "C:\Users\jay\AppData\Roaming\Python\Python313\site-packages\pydoll\browser\managers\temp_dir_manager.py", line 86, in handle_cleanup_error
    raise exc_value
  File "C:\Program Files\Python313\Lib\shutil.py", line 625, in _rmtree_unsafe
    os.unlink(fullname)
    ~~~~~~~~~^^^^^^^^^^
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\jay\\AppData\\Local\\Temp\\tmpxjv2xjox\\optimization_guide_model_store\\25\\E6DC4029A1E4B4C1\\99D314CC33247C89\\visual_model_desktop.tflite'
Traceback (most recent call last):
  File "C:\Program Files\Python313\Lib\shutil.py", line 625, in _rmtree_unsafe
    os.unlink(fullname)
    ~~~~~~~~~^^^^^^^^^^
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\jay\\AppData\\Local\\Temp\\tmpxjv2xjox\\optimization_guide_model_store\\25\\E6DC4029A1E4B4C1\\99D314CC33247C89\\visual_model_desktop.tflite'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python313\Lib\weakref.py", line 666, in _exitfunc
    f()
    ~^^
  File "C:\Program Files\Python313\Lib\weakref.py", line 590, in __call__
    return info.func(*info.args, **(info.kwargs or {}))
           ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python313\Lib\tempfile.py", line 939, in _cleanup
    cls._rmtree(name, ignore_errors=ignore_errors)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python313\Lib\tempfile.py", line 934, in _rmtree
    _shutil.rmtree(name, onexc=onexc)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python313\Lib\shutil.py", line 790, in rmtree
    return _rmtree_unsafe(path, onexc)
  File "C:\Program Files\Python313\Lib\shutil.py", line 629, in _rmtree_unsafe
    onexc(os.unlink, fullname, err)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python313\Lib\tempfile.py", line 909, in onexc
    _os.unlink(path)
    ~~~~~~~~~~^^^^^^
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\jay\\AppData\\Local\\Temp\\tmpxjv2xjox\\optimization_guide_model_store\\25\\E6DC4029A1E4B4C1\\99D314CC33247C89\\visual_model_desktop.tflite'

EDIT: This error is intermittent, and happens around 20% of the time

radiantly avatar Jul 17 '25 17:07 radiantly