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

Error flask_gravatar with flask 3.0.0 #31

Open
Canfry opened this issue Nov 8, 2023 · 5 comments
Open

Error flask_gravatar with flask 3.0.0 #31

Canfry opened this issue Nov 8, 2023 · 5 comments

Comments

@Canfry
Copy link

Canfry commented Nov 8, 2023

Trying to use flask_gravatar in my project but have the following error when running the app with Gravatar:
ImportError: cannot import name '_request_ctx_stack' from 'flask'

  • Python version: 3.12
  • Flask version: 3.0.0
  • flask_gravatar version: 0.5.0
    The whole app is working perfectly until I use the documentation exemple:
    from flask_gravatar import Gravatar

gravatar = Gravatar(app, size=100, rating='g', default='retro', force_default=False, force_lower=False, use_ssl=False, base_url=None)

User Icon

@animitchel
Copy link

I am currently experiencing the same issue, after upgrading Flask to version, 3.0.0. i guess the flask_gravatar 0.5.0 is not compatible with it. Have you found any solution to this problem since?

@animitchel
Copy link

animitchel commented Nov 20, 2023

Well i found a solution, remove anything flask_gravatar from your code and define gravatar as a function instead and integrate into your html. here is the function example:

def gravatar_url(email, size=100, rating='g', default='retro', force_default=False):
hash_value = md5(email.lower().encode('utf-8')).hexdigest()
return f"https://www.gravatar.com/avatar/{hash_value}?s={size}&d={default}&r={rating}&f={force_default}"

This overrides the default function, so its now a custom function

i hope that helps you

@Canfry
Copy link
Author

Canfry commented Nov 20, 2023

Thank you so much yes it works like this 👍👍👍👍

@gar-rock
Copy link

Gravatar is a pretty common tool that more Flask folks are going to want to use in updated Flask versions.
If we could get some traction on this that would be great!
I would also be happy to help contribute if I could.

@gar-rock
Copy link

Well i found a solution, delete anything flask_gravatar from your code and define gravatar as a function instead and integrate into your html. here is the function example:

def gravatar_url(email, size=100, rating='g', default='retro', force_default=False): hash_value = md5(email.lower().encode('utf-8')).hexdigest() return f"https://www.gravatar.com/avatar/{hash_value}?s={size}&d={default}&r={rating}&f={force_default}"

i hope that helps you

This worked for me, but I had to use sha256 following this gravatar doc

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

No branches or pull requests

3 participants