question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FileNotFoundError when calling info

See original GitHub issue

When calling info on a file that has been uploaded to S3 after info has already been called on another file in the same prefix, s3fs reports a FileNotFoundError, here’s a code snippet that reproduces the behaviour.

import s3fs
import boto3


bucket_name = "bucket"
prefix = "data"

s3 = s3fs.S3FileSystem()
bucket = boto3.resource('s3').Bucket(bucket_name)

def test(filename):
    key = f"{prefix}/{filename}"
    with open(filename, 'rb') as data:
        bucket.upload_fileobj(data, key)
    info = s3.info(f"{bucket_name}/{key}")
    print(f"{key} info: {info}")


def main():
    test("file1")
    test("file2")


if __name__ == "__main__":
    main()

output:

python s3fs_info_test.py
data4/file1 info: {'Key': 'bucket/data/file1', 'LastModified': datetime.datetime(2019, 9, 13, 17, 30, 16, tzinfo=tzutc()), 'ETag': '"664888fac652413c3a57c2e669d5d2b5"', 'Size': 151645, 'StorageClass': 'STANDARD', 'type': 'file', 'size': 151645, 'name': 'bucket/data/file1'}
Traceback (most recent call last):
  File "s3fs_info_test.py", line 25, in <module>
    main()
  File "s3fs_info_test.py", line 21, in main
    test("file2")
  File "s3fs_info_test.py", line 15, in test
    info = s3.info(f"{bucket_name}/{key}")
  File "/home/steve/.virtualenvs/partition_stats-RqvIULMs/lib/python3.7/site-packages/s3fs/core.py", line 498, in info
    return super().info(path)
  File "/home/steve/.virtualenvs/partition_stats-RqvIULMs/lib/python3.7/site-packages/fsspec/spec.py", line 509, in info
    raise FileNotFoundError(path)
FileNotFoundError: bucket/data/file2

Not sure if it’s the best way to fix it (or if it even does fix the issue) but in def info you could try wrapping return super().info(path) in a try/except and if it’s a FileNotFoundError, call info again but pass refresh=True.

The use case for us is that we have a lambda subscribed to bucket notifications for objects that are created, and what is happening is that when the lambda container is reused consecutive files that are uploaded to the same prefix fail with a FileNotFoundError. After some time goes by (long enough to get a fresh lambda container) retrying the same bucket notification event works fine.

For now we’ve pinned at 0.2.1, which doesn’t have this bug.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
martindurantcommented, Sep 18, 2019

It is a valid argument. Please make a PR with this change, and encourage other team members to discuss.

0reactions
rambej0201commented, Feb 10, 2020

@martindurant I actually got FIleNotFoundError for some events during 05Feb2020 than I made sure about s3.invalidate_cache() on the API

Read more comments on GitHub >

github_iconTop Results From Across the Web

FileNotFoundError when calling info · Issue #238 · fsspec/s3fs
When calling info on a file that has been uploaded to S3 after info has already been called on another file in the...
Read more >
[SOLVED] Python filenotfounderror - A Quick Guide - AskPython
It is a system message that the compiler throws when you are trying to execute a command that requires a file that the...
Read more >
python - Why am I getting a FileNotFoundError? - Stack Overflow
In order to make this work, the directory containing the python executable must be in the PATH, a so-called environment variable that contains ......
Read more >
Python FileNotFoundError: [Errno 2] No such file or directory ...
Any message with the contents FileNotFoundError indicates that Python cannot find the file you are referencing. Python raises this error because your program ......
Read more >
FileNotFoundError: [Errno 2] No such ... - Net-Informations.Com
When you open a file with the name "filename.ext"; you are telling the open() function that your file is in the current working...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found