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

send_file throwing an error in werkzeug by passing a None-type to function that requires str #153

Open
scoofy opened this issue Jan 11, 2022 · 2 comments · Fixed by ymercad0/pathway#15

Comments

@scoofy
Copy link

scoofy commented Jan 11, 2022

I upgraded to python 3.9 and i've run into some problems. When running:

mongo.send_file(filename)

Running tests, when I'm grabbing an image file from my mongo database, it seems to not be returning an MD5 in the fileobj, which causes an error here:

response.set_etag(fileobj.md5)

this seems to throw an error with werkzeug/http.py

line 850, in quote_etag
if '"' in etag:

TypeError: argument of type 'NoneType' is not iterable

I'm not exactly sure if this is the fault of flask-pymongo, or why i'm getting the error. But when i remove the set_etag line, it works just fine. The werkzeug file has a type hint that the etag must be a str, so it seems that you may want to turn a None instance into an empty string before running that function.

@scoofy
Copy link
Author

scoofy commented Jan 11, 2022

I realized the issue is a PyMongo 3.x -> 4 problem.

@shigongqiang
Copy link

GridFS changes
disable_md5 parameter is removed
Removed the disable_md5 option for GridFSBucket and GridFS. GridFS no longer generates checksums. Applications that desire a file digest should implement it outside GridFS and store it with other file metadata. For example:

import hashlib
my_db = MongoClient().test
fs = GridFSBucket(my_db)
grid_in = fs.open_upload_stream("test_file")
file_data = b'...'
sha356 = hashlib.sha256(file_data).hexdigest()
grid_in.write(file_data)
grid_in.sha356 = sha356 # Set the custom 'sha356' field
grid_in.close()
Note that for large files, the checksum may need to be computed in chunks to avoid the excessive memory needed to load the entire file at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants