botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden

0

I am trying to run my code.

from lithops.multiprocessing import Pool import time import s3fs

s3 = s3fs.S3FileSystem(anon=True)

def count_words(lines): count = 0 for line in lines: line = line.rstrip() pieces = line.split() for initial_word in pieces: word = ''.join(c for c in initial_word if c.isalpha()) if word: # Skip empty words count = count + 1 return count

if name == 'main': fhand = s3.open('lithops-data-yey/notsobigtextfile_small.txt')

start = time.perf_counter()

word_number = 0
lines_per_chunk = 1000  # Number of lines to process per chunk

with Pool() as p:
    chunks = []
    while True:
        chunk = []
        for _ in range(lines_per_chunk):
            line = fhand.readline()
            if not line:
                break
            chunk.append(line)
        if not chunk:
            break
        chunks.append(chunk)

    line_numbers = p.map(count_words, chunks)

word_number = sum(line_numbers)

print('Word Count:', word_number)

finish = time.perf_counter()

print(f'Finished in {round(finish - start, 2)} second(s)')

I want to figure out why I get the error on the line fhand = s3.open('lithops-data-yey/notsobigtextfile_small.txt') I've made sure my credentials file is correct and don't know how to proceed. This is the error I get: Exception has occurred: PermissionError Forbidden botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden

The above exception was the direct cause of the following exception:

File "/Users/oanamoc/Desktop/Work/lithops/task1 copy.py", line 20, in <module> fhand = s3.open('lithops-data-yey/notsobigtextfile_small.txt') PermissionError: Forbidden

oanamoc
asked 10 months ago2951 views
1 Answer
0

Make sure you have permission to s3:putObject, s3:getObject and s3:listBuckets.

profile picture
EXPERT
answered 10 months ago
  • How do I make sure of that?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions