requests-html icon indicating copy to clipboard operation
requests-html copied to clipboard

PermissionError: [WinError 5] Access is denied

Open chisox721 opened this issue 6 years ago • 28 comments

Taking a shot in the dark here and hoping someone can point me in the right direction as to why I'm getting this error. I have used this same script in the past without issue so I'm completely lost as to what happened. Any help/suggestions would be greatly appreciated.

from requests_html import HTMLSession

link = 'https://www.denvergov.org/property/realproperty/summary/160820474'
session = HTMLSession()
url = session.get(link)
print(url)

<Response [200]>

url.html.render()

Traceback (most recent call last):
  File "C:/Users/Nick/gfddfsf.py", line 9, in <module>
    url.html.render()
  File "C:\Users\Nick\lib\site-packages\requests_html.py", line 572, in render
    self.session.browser  # Automatycally create a event loop and browser
  File "C:\Users\Nick\lib\site-packages\requests_html.py", line 680, in browser
    self._browser = self.loop.run_until_complete(pyppeteer.launch(headless=True, args=['--no-sandbox']))
  File "C:\Users\Nick\lib\asyncio\base_events.py", line 467, in run_until_complete
    return future.result()
  File "C:\Users\Nick\lib\site-packages\pyppeteer\launcher.py", line 311, in launch
    return await Launcher(options, **kwargs).launch()
  File "C:\Users\Nick\lib\site-packages\pyppeteer\launcher.py", line 169, in launch
    **options,
  File "C:\Users\Nick\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Nick\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Access is denied

chisox721 avatar Jan 08 '19 22:01 chisox721

Try running as an administrator. I believe Windows puts restrictions on programs starting new processes like the subprocess module is trying to do in the traceback. Run through an administrator command prompt/PowerShell (obviously on an administrator account) and see if you get better results.

Sarcastic-Pharm avatar Jan 09 '19 01:01 Sarcastic-Pharm

Try running as an administrator. I believe Windows puts restrictions on programs starting new processes like the subprocess module is trying to do in the traceback. Run through an administrator command prompt/PowerShell (obviously on an administrator account) and see if you get better results.

Thanks for the response but I got the same result unfortunately. This is really frustrating because it's my computer and I'm the only user so being denied access to anything is pretty ridiculous. On top of that I've successfully ran the same script in the past so either it has something to do with a Windows update or I accidentally messed with something I shouldn't have.

chisox721 avatar Jan 11 '19 00:01 chisox721

No worries. I'm off camping right now so can't have a run at the issue myself. I've had a look at a few SO answers on the same subprocess error and a lot of them look to be related to incorrect or incomplete file paths to drivers or similar. Are you running in a virtual environment or just using the system installation of python?

Either way, I'd try making a fresh virtual environment with a fresh installation of whatever libraries your script runs and see if it still errors out.

If it still errors after that then we can take a run at your operating system as a culprit.

Sarcastic-Pharm avatar Jan 11 '19 00:01 Sarcastic-Pharm

I use jupyter once in awhile but haven't ran this script on it. 99% of my scripts use the system install.

Tried reinstalling the libraries, no luck there. At this point I'm pretty sure I must've changed a setting accidentally but attempting to figure out exactly what I changed seems like trying to find a needle in a haystack.

chisox721 avatar Jan 17 '19 20:01 chisox721

Hi. If you use Python 3.7.2, then update to 3.7.3. Python 3.7.2 contained bug - https://bugs.python.org/issue35797

sergey-shuyskiy avatar Apr 08 '19 10:04 sergey-shuyskiy

I use jupyter once in awhile but haven't ran this script on it. 99% of my scripts use the system install.

Tried reinstalling the libraries, no luck there. At this point I'm pretty sure I must've changed a setting accidentally but attempting to figure out exactly what I changed seems like trying to find a needle in a haystack.

Any luck on finding a solution? Did the update from 3.7.2 to 3.7.3 solution work for you?

I have a very similar "PermissionError: [WinError 5] Access is denied", but caused by the n_jobs = -1 in the function cross_val_score(...) from sklearn.model_selection. Running cmd as admin and updating to 3.7.3 did not fix my problem.

soopnoods avatar Apr 10 '19 21:04 soopnoods

I have nearly the exact same issue as @LemonCakeXD above. I have the latest 3.7.3, have tried "run as admin", etc. Only way for it to work is for me to set n_jobs=1. I'd rather not have that as the workaround though and prefer to use the full hw resources available on my dev box.

eunpingco avatar Jul 08 '19 21:07 eunpingco

I got it working after a lot of debugging inside my code. In my case, the permission problem was because of the way I opened the image img = cv2.imread('G:/project/OCR/FDA.png')

Changed that code by adding a prefix 'r' before the path.

img = cv2.imread(r'G:/project/OCR/FDA.png')

Make sure you give the full path to the image. This worked for and got rid of the permission problem.

Can anyone check and tell if this solved your permission problem ?

saikrishnadas avatar Jan 21 '20 05:01 saikrishnadas

Hi team I am Facing the following issue

Traceback (most recent call last): File "C:/Users/Admin/AppData/Local/Programs/Python/Python37/demo9.py", line 9, in result=pytesseract.image_to_string(img) File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pytesseract\pytesseract.py", line 347, in image_to_string }output_type File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pytesseract\pytesseract.py", line 346, in Output.STRING: lambda: run_and_get_output(*args), File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pytesseract\pytesseract.py", line 262, in run_and_get_output return output_file.read().decode('utf-8').strip() File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\contextlib.py", line 119, in exit next(self.gen) File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pytesseract\pytesseract.py", line 174, in save cleanup(f.name) File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pytesseract\pytesseract.py", line 134, in cleanup raise e File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pytesseract\pytesseract.py", line 131, in cleanup remove(filename) PermissionError: [WinError 5] Access is denied: 'C:\Users\Admin\AppData\Local\Temp\tess_8k7nta5f'

ShubhamBirhade1 avatar Feb 01 '20 10:02 ShubhamBirhade1

Having the same issue, with python 3.8 anyone. Have already tried all the above still not working

ghost avatar Apr 21 '20 15:04 ghost

I recently faced a similar issue. In my case it was similar to the OP's issue with subprocess.py and PermissionError: [WinError 5] Access is denied.

The displayed error is very misleading, but in my case there was an executable required for a subprocess, and I had only specified the directory containing the executable. Completing the path the the executable solved the issue.

Now that I have it solved, I understand the Permission Error description (the script can't access the required executable) but that was not obvious to me when first debugging.

ADVEngr avatar May 01 '20 13:05 ADVEngr

Facing the same issue while unistall TensorFlow ==1.15 from the system

maverick-27 avatar May 05 '20 19:05 maverick-27

Exception in Tkinter callback Traceback (most recent call last): File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\tkinter_init_.py", line 1705, in call return self.func(*args) File "C:\GIS\PropertyAppraiser\kmulcahy\python\python_codes\PDFtoTXTForAllFormat.py", line 833, in imgps text = pytesseract.image_to_string(Image.open(temp_path)) File "C:\Users\NassauUser\AppData\Roaming\Python\Python36\site-packages\pytesseract\pytesseract.py", line 362, in image_to_string }output_type File "C:\Users\NassauUser\AppData\Roaming\Python\Python36\site-packages\pytesseract\pytesseract.py", line 361, in Output.STRING: lambda: run_and_get_output(*args), File "C:\Users\NassauUser\AppData\Roaming\Python\Python36\site-packages\pytesseract\pytesseract.py", line 272, in run_and_get_output run_tesseract(**kwargs) File "C:\Users\NassauUser\AppData\Roaming\Python\Python36\site-packages\pytesseract\pytesseract.py", line 243, in run_tesseract raise e File "C:\Users\NassauUser\AppData\Roaming\Python\Python36\site-packages\pytesseract\pytesseract.py", line 240, in run_tesseract proc = subprocess.Popen(cmd_args, **subprocess_args()) File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\subprocess.py", line 729, in init restore_signals, start_new_session) File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\subprocess.py", line 1017, in _execute_child startupinfo) PermissionError: [WinError 5] Access is denied

what is the solution?

kathysll avatar May 08 '20 14:05 kathysll

I got it working after a lot of debugging inside my code. In my case, the permission problem was because of the way I opened the image img = cv2.imread('G:/project/OCR/FDA.png')

Changed that code by adding a prefix 'r' before the path.

img = cv2.imread(r'G:/project/OCR/FDA.png')

Make sure you give the full path to the image. This worked for and got rid of the permission problem.

Can anyone check and tell if this solved your permission problem ?

This worked for me, had issues in the path i used.

malihanan avatar May 31 '20 11:05 malihanan

Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] Type "copyright", "credits" or "license" for more information.

IPython 7.16.1 -- An enhanced Interactive Python.

import os from flask import Flask, request, redirect, url_for, render_template, send_from_directory,flash from werkzeug.utils import secure_filename import ocrmypdf import glob from zipfile import ZipFile

os.chdir(r"C:\Users\Popeye\Desktop\OD\POC\APP\downloads")

os.chdir(r"C:\Users\Popeye\Desktop\OD\POC\APP\uploads")

test = r"C:\Users\Popeye\Desktop\OD\POC\APP\uploads"

os.remove(test) Traceback (most recent call last):

File "", line 1, in os.remove(test)

PermissionError: [WinError 5] Access is denied: 'C:\Users\Popeye\Desktop\OD\POC\APP\uploads'

This is really frustrating.... 👎

Can Anyone help ??

insanepopeye avatar Aug 30 '20 09:08 insanepopeye

Adding /tesseract to the file path worked for me. For example: "C:\Users\Popeye\Desktop\OD\POC\APP\downloads\tesseract". It needs the full path to the exe.

khazaddim avatar Sep 25 '20 03:09 khazaddim

I got mine to work by...

  1. Following the 3rd bullet under the heading INSTALLATION on this page https://pypi.org/project/pytesseract/ 1a. I installed the 64 bit executable installer from UB Mannheim 1b. Note: I didn't think this was necessary because there was a pytesseract.exe in my C:\Users\name\AppData\Roaming\Python\Python38\Scripts directory. Apparently, that exe is for something else. Not sure.

I continued by...

  1. Adding the directory where tesseract.exe was actually installed to my windows path (see below). (Logging off and back on to the windows machine)

and... 3. Changing my code to this: 3a. Note the r in front of the strings to signify that they are 'raw' strings, meaning don't use escape characters in them.

pytesseract.pytesseract.tesseract_cmd = r'C:\Users\name\AppData\Local\Tesseract-OCR\tesseract.exe'

im5 = Image.open(r'C:\g\code\assistant\portion.png')

print(pytesseract.image_to_string(im5))

The printed output looks a little rough, but at least I got this far. (here's a sample if you're curious) Hw @ emaillink [help [PT MM messages [Ml calendar, contacts | tutor Pe Moura

These are theoretically the names of the shortcuts on my browser. Screenshot 2020-11-22 171438

davidpluseipi avatar Nov 23 '20 01:11 davidpluseipi

I got it working after a lot of debugging inside my code. In my case, the permission problem was because of the way I opened the image img = cv2.imread('G:/project/OCR/FDA.png') Changed that code by adding a prefix 'r' before the path. img = cv2.imread(r'G:/project/OCR/FDA.png') Make sure you give the full path to the image. This worked for and got rid of the permission problem. Can anyone check and tell if this solved your permission problem ?

This worked for me, had issues in the path i used.

Thanks it worked for me too

dhamejanishivam avatar Dec 25 '20 08:12 dhamejanishivam

Thanks

dhamejanishivam avatar Dec 25 '20 08:12 dhamejanishivam

switch the direction of the slashes make it like that subprocess.call('C://Users/tamer/AppData/Roaming/Zoom/bin/zoom.exe')

not like that subprocess.call('C:\Users\tamer\AppData\Roaming\Zoom\bin\zoom.exe')

tamersaeed avatar Mar 25 '21 20:03 tamersaeed

Found this useful and related https://stackoverflow.com/questions/1889597/deleting-read-only-directory-in-python

leenjiru avatar May 31 '22 09:05 leenjiru

I worked around this error when invoking rmtree() by explicitly fixing the permissions before exiting the TemporaryDirectory() context manager. See akaihola/darker#453.

akaihola avatar Jan 07 '23 10:01 akaihola

No worries. I'm off camping right now so can't have a run at the issue myself. I've had a look at a few SO answers on the same subprocess error and a lot of them look to be related to incorrect or incomplete file paths to drivers or similar. Are you running in a virtual environment or just using the system installation of python?

Either way, I'd try making a fresh virtual environment with a fresh installation of whatever libraries your script runs and see if it still errors out.

If it still errors after that then we can take a run at your operating system as a culprit.

Hi! I'm facing the same Access denied issue with my Windows11 OS. I already tried your suggestion to run in Admin Terminal.

Ithikasha avatar Mar 06 '23 07:03 Ithikasha

I got mine to work by...

1. Following the 3rd bullet under the heading INSTALLATION on this page https://pypi.org/project/pytesseract/
   1a. I installed the 64 bit executable installer from UB Mannheim
   1b. Note: I didn't think this was necessary because there was a pytesseract.exe in my C:\Users\name\AppData\Roaming\Python\Python38\Scripts directory.  Apparently, that exe is for something else. Not sure.

I continued by...

2. Adding the directory where tesseract.exe was actually installed to my windows path (see below). (Logging off and back on to the windows machine)

and... 3. Changing my code to this: 3a. Note the r in front of the strings to signify that they are 'raw' strings, meaning don't use escape characters in them.

pytesseract.pytesseract.tesseract_cmd = r'C:\Users\name\AppData\Local\Tesseract-OCR\tesseract.exe'

im5 = Image.open(r'C:\g\code\assistant\portion.png')

print(pytesseract.image_to_string(im5))

The printed output looks a little rough, but at least I got this far. (here's a sample if you're curious) Hw @ emaillink [help [PT MM messages [Ml calendar, contacts | tutor Pe Moura

These are theoretically the names of the shortcuts on my browser. Screenshot 2020-11-22 171438

That workt for me. I faced the same problem with pytesserract.

Kassy607 avatar May 16 '23 21:05 Kassy607

I worked around this error when invoking rmtree() by explicitly fixing the permissions before exiting the TemporaryDirectory() context manager. See akaihola/darker#453.

Hey, I am getting this error for rmtree() as well, didn't understand the solution you mentioned, can you please help on how to resolve?

k7kaushal avatar Nov 14 '23 13:11 k7kaushal

I tried to run image to string convert program in python using pytesseract. I am using VS code with Jupyter Extension and Python 3.12.0 installed. I am facing error in pytesseract.image_to_string......

`from PIL import Image

import pytesseract

pytesseract.pytesseract.tesseract_cmd = r'C:\Users\KP\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytesseract'

image = Image.open("readonly/text.png")

text = pytesseract.image_to_string(image) print(text)

PermissionError Traceback (most recent call last) c:\Users\KP\Downloads\Python Project pillow, tesseract, and opencv\Week-2\Jupitor files\module_2.ipynb Cell 9 line 2 1 # One last thing to mention - the image_to_string() function takes in an "image", but the docs don't 2 # really describe what this image is underneath. Is it a string to an image file? A PILLOW image? 3 # Something else? (...) 27 # 28 # Ok, lets try and run tesseract on this image ---> 29 text = pytesseract.image_to_string(image) 30 print(text)

File c:\Users\KP\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytesseract\pytesseract.py:423, in image_to_string(image, lang, config, nice, output_type, timeout) 418 """ 419 Returns the result of a Tesseract OCR run on the provided image to string 420 """ 421 args = [image, 'txt', lang, config, nice, timeout] --> 423 return { 424 Output.BYTES: lambda: run_and_get_output(*(args + [True])), 425 Output.DICT: lambda: {'text': run_and_get_output(*args)}, 426 Output.STRING: lambda: run_and_get_output(*args), 427 }output_type

File c:\Users\KP\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytesseract\pytesseract.py:426, in image_to_string..() 418 """ ... 898 cmd_line = patch_arg_str_win(cmd_line) 899 send_process_created_message() --> 901 return getattr(_subprocess, original_name)(app_name, cmd_line, *args)

PermissionError: [WinError 5] Access is denied'

Any solution for error..........

jaydattpatel avatar Mar 01 '24 05:03 jaydattpatel