Why am I getting a "Permission denied" error on Google Cloud VM?

60 views Asked by At

I've uploaded my python bot to a Google Cloud VM instance and I'm trying to save a file to my working directory. Here's what I run in the command line:

sudo git clone {github}
cd CE-Assistant
python3 main.py

This is the code that is erroring:

path = Path("/CE-Assistant/part{0}.png".format(part)) # create the path to save
ss = driver.get_screenshot_as_png() # acquire the screenshot
path.parent.mkdir(parents=True, exist_ok=True) # THIS IS WHERE THE ERROR IS 
with open(path, "wb") as ss_file:
                    print('with open')
                    ss_file.write(ss)
                    print("Svreenshot saved")

And this is the error I'm getting:

Traceback (most recent call last):
  File "/home/andrewgarcha/.local/lib/python3.9/site-packages/discord/app_commands/commands.py", line 828, in _do_call
    return await self._callback(interaction, **params)  # type: ignore
  File "/home/andrewgarcha/CE-Assistant/main.py", line 523, in test
    await master_loop(client, mongo_client)
  File "/home/andrewgarcha/.local/lib/python3.9/site-packages/discord/ext/tasks/__init__.py", line 368, in __call__
    return await self.coro(*args, **kwargs)
  File "/home/andrewgarcha/CE-Assistant/Web_Interaction/loopty_loop.py", line 150, in master_loop
    await scrape(correct_channel, mongo_client)
  File "/home/andrewgarcha/CE-Assistant/Web_Interaction/loopty_loop.py", line 202, in scrape
    updates = await thread_scrape(database_name, curator_count) #asyncio.to_thread(thread_scrape)
  File "/home/andrewgarcha/CE-Assistant/Web_Interaction/loopty_loop.py", line 184, in wrapper
    return await asyncio.to_thread(func, *args, **kwargs)
  File "/usr/lib/python3.9/asyncio/threads.py", line 25, in to_thread
    return await loop.run_in_executor(None, func_call)
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/andrewgarcha/CE-Assistant/Web_Interaction/loopty_loop.py", line 222, in thread_scrape
    return get_games(database_name, curator_count)
  File "/home/andrewgarcha/CE-Assistant/Web_Interaction/scraping.py", line 51, in get_games
    fin = game_list(database_name, curator_count)
  File "/home/andrewgarcha/CE-Assistant/Web_Interaction/scraping.py", line 131, in game_list
    get_image(0, "1e866995-6fec-452e-81ba-1e8f8594f4ea", driver)
  File "/home/andrewgarcha/CE-Assistant/Web_Interaction/scraping.py", line 736, in get_image
    im = ob.full_screenshot(driver, save_path=r'Pictures/', image_name="ss{}.png".format(number), is_load_at_runtime=True, load_wait_time=10, hide_elements=header_elements)
  File "/home/andrewgarcha/CE-Assistant/Web_Interaction/Screenshot.py", line 141, in full_screenshot
    path.parent.mkdir(parents=True, exist_ok=True)
  File "/usr/lib/python3.9/pathlib.py", line 1312, in mkdir
    self._accessor.mkdir(self, mode)
PermissionError: [Errno 13] Permission denied: 'CE-Assistant'

I was getting this error before - when I was saving it to a different folder in the working directory. I was trying to save it to /home/andrewgarcha/CE-Assistant/Pictures/ by just using the path /Pictures, and solved it by replacing it with /CE-Assistant/Pictures, since /CE-Assistant is my working directory. But yesterday, I upgraded from a 0.25 vCPU plan to a 2 vCPU plan - and this is the only thing I changed, so I assume it's the problem - and now this solution isn't working anymore. I have tried /Pictures, I have tried /home/andrewgarcha/CE-Assistant/Pictures, and I have no idea how to get this to go away.

P.S. I'm now just saving them to my working directory, instead of /Pictures, if that helps this code make any more sense.

0

There are 0 answers