简体   繁体   中英

ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} while trying to run an image down loader on Python using Selenium

the code runs fine until it tries to access the directory. any input is appreciated thanks

Here is the code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os
import ast
import requests
import urllib.request
from bs4 import BeautifulSoup as Soup


opts = Options()

opts.add_argument("user-agent=chrome/23.0.1271")

driver = webdriver.Chrome("./chromedriver.exe")

url = 'https://s.aolcdn.com/os/ab/_cms/2020/09/09081722/568224.jpg'
directory = 'RAW'
FILETYPE = '.jpg'

r = requests.get(url,allow_redirects=True)



def find_urls(url):
    driver.get(url)
    wait = input('loading...lmao')
    page = driver.page_source

    soup = Soup(page,'lxml')
    images = soup.find_all('img',{"src":True})

all_images = []

for image in images:
    image_src = image['src']
    print(image_src)
    
    urllib.request.urlretrieve(image_src)


Images = find_urls(url)





def save_img(Image,directory):
    if not os.path.isdir(directory):
        os.mkdir(directory)

            
for i,link in enumerate(url):
    path = os.path.join(directory,'(:06).jpg'.format(i))
    try:
        ulib.urlretrieve(link,path)
    except:
        print('Failed:')

            
save_img(Images,directory)

I think might be how I access the directory but I'm running out of things to try I've checked the folder made sure to run as admin.

This error message...

ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied}

...implies that the ChromeDriver initiated thread was unable to read the system resource as access was denied.


Root Cause

A common cause for Access Denied is running Chrome as root user ( administrator ) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.


Additional Consideration

Ensure that:

  • Selenium is upgraded to current released Version 3.141.59 .
  • ChromeDriver is updated to current ChromeDriver v84.0 level.
  • Chrome is updated to current Chrome Version 84.0 level. (as per ChromeDriver v84.0 release notes )
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client .
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Take a System Reboot .
  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM