Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage download failing due to JSON decode #721

Closed
ddematheu opened this issue Mar 10, 2024 · 7 comments · Fixed by supabase-community/storage-py#203
Closed

Storage download failing due to JSON decode #721

ddematheu opened this issue Mar 10, 2024 · 7 comments · Fixed by supabase-community/storage-py#203
Labels
bug Something isn't working

Comments

@ddematheu
Copy link

ddematheu commented Mar 10, 2024

Bug report

Describe the bug

download method is throwing an exception when downloading a file.

To Reproduce

Initialize supabase client and attempt to download a file using method:

response = supabase.storage.from_(bucket_name).download(file_path)

response = supabase.storage.from_(bucket_name).list(path)

Throws Error: Expecting value: line 1 column 1 (char 0)

Trace:
Traceback (most recent call last):
File "/app/supabase_utils/download_utils.py", line 39, in download_with_retry
response = supabase.storage.from_(bucket_name).download(file_path)
File "/usr/local/lib/python3.10/site-packages/storage3/_sync/file_api.py", line 339, in download
response = self._request(
File "/usr/local/lib/python3.10/site-packages/storage3/_sync/file_api.py", line 49, in _request
{**response.json(), "statusCode": response.status_code}
File "/usr/local/lib/python3.10/site-packages/httpx/_models.py", line 761, in json
return jsonlib.loads(self.content, **kwargs)
File "/usr/local/lib/python3.10/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Expected behavior

File is downloaded if its available or 400 is returned if the file is not available.

System information

  • OS: Linux

Additional context

Add any other context about the problem here.

Seeing error across version 2.3.6-2.4.0

@ddematheu ddematheu added the bug Something isn't working label Mar 10, 2024
@ddematheu
Copy link
Author

We are seeing a 403 error thrown. Seems transient as making the same request again will work.

@ddematheu
Copy link
Author

Example request: (removed some values for security purposes)

HTTP Request: GET https://[BASE SUPABASE URL]/storage/v1/object/[BUCKET]/[FOLDER]/[FILE] "HTTP/1.1 403 Forbidden"

@kiwicopple
Copy link
Contributor

Hey @ddematheu, thanks for the report

Seems transient as making the same request again will work

Is there a possibility of a race-condition where the user is not yet logged in when making a request? If you log (before) each request can you see that the headers include the authorization code?

(Did you make any changes to your own application before 1030 PT? We haven't made any changes this weekend, and we aren't seeing this across other customers)

@J0
Copy link
Collaborator

J0 commented Mar 10, 2024

Hey @ddematheu,

Thanks for the query - we've are looking into the issue. It looks like we might need to update the error handling

If possible, can I trouble you for the code surrounding the section where the .download() is called? Would also be helpful to know if the bucket is currently protected and if you have a file or URL that we can replicate this with.

Let us know!

@ddematheu
Copy link
Author

ddematheu commented Mar 10, 2024

@J0

Saw the fix that was introduced for 0.7.1. It contains another bug:

NameError: name 'JSONDecodeError' is not defined

The bucket in questions has an RLS policy to allow only authenticated users and our anon key access. That said we are using our service role key to access the files from our backend.

happy to provide more details for repro, but would prefer to do it via email if that is okay. [email protected]

@silentworks
Copy link
Contributor

@ddematheu please check 0.7.3 which should fix the NameError: name 'JSONDecodeError' is not defined issue.

@J0
Copy link
Collaborator

J0 commented Mar 11, 2024

Hey @ddematheu,

Apologies I think an import was missed which @silentworks has patched 🙏

Will send over an email from support channel in a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants