cannot import name ‘_endpoint_from_view_func’ from ‘flask.helpers’ in python

We Are Going To Discuss About cannot import name ‘_endpoint_from_view_func’ from ‘flask.helpers’ in python. So lets Start this Python Article.

cannot import name ‘_endpoint_from_view_func’ from ‘flask.helpers’ in python

  1. How to solve cannot import name '_endpoint_from_view_func' from 'flask.helpers' in python

    That's a known issue that awaits to be solved here.
    In the meantime, I suggest a monkey patching:
    import flask.scaffold flask.helpers._endpoint_from_view_func = flask.scaffold._endpoint_from_view_func import flask_restful ...
    For reference, the current version of my Flask-RESTful package is 0.3.8.

    Edit:
    Since the issue has then been fixed in release 0.3.9, just upgrade the package version:
    Flask-RESTful>0.3.8

  2. cannot import name '_endpoint_from_view_func' from 'flask.helpers' in python

    That's a known issue that awaits to be solved here.
    In the meantime, I suggest a monkey patching:
    import flask.scaffold flask.helpers._endpoint_from_view_func = flask.scaffold._endpoint_from_view_func import flask_restful ...
    For reference, the current version of my Flask-RESTful package is 0.3.8.

    Edit:
    Since the issue has then been fixed in release 0.3.9, just upgrade the package version:
    Flask-RESTful>0.3.8

Solution 1

That’s a known issue that awaits to be solved here.

In the meantime, I suggest a monkey patching:

import flask.scaffold
flask.helpers._endpoint_from_view_func = flask.scaffold._endpoint_from_view_func
import flask_restful
...

For reference, the current version of my Flask-RESTful package is 0.3.8.


Edit:

Since the issue has then been fixed in release 0.3.9, just upgrade the package version:

Flask-RESTful>0.3.8

Original Author renatodamas Of This Content

Solution 2

Like Renato mentioned, this is a known issue.
The team has fixed it.
Using a recent version of Flask-RESTful fixed the issue for me.
For example:

Flask-RESTful==0.3.9

Original Author Iching Chang Of This Content

Solution 3

Here is a monkey patch. You can define your own _endpoint_from_view_func or use flask.scaffold._endpoint_from_view_func as mentioned in answer of @RenatoDamas

# monkey.py

def _endpoint_from_view_func(view_func):
    """Internal helper that returns the default endpoint for a given
    function.  This always is the function name.
    """
    assert view_func is not None, "expected view func if endpoint is not provided."
    return view_func.__name__


# noinspection SpellCheckingInspection
def patch_restx(endpoint_from_view_func: bool = True) -> None:
    """
    Nasty hacks are here

    :param endpoint_from_view_func: Add missing function into flask for backward compatibility with `flask-restx`
    """
    if endpoint_from_view_func:
        func_name = "_endpoint_from_view_func"
        try:
            import pkg_resources
            packages = pkg_resources.working_set.by_key
            if "flask" in packages and "flask-restx" in packages:
                flask_version = tuple(map(int, packages["flask"].version.split(".")))
                flask_restx_version = tuple(map(int, packages["flask-restx"].version.split(".")))
                if (2, 0, 0) <= flask_version and (1, 0, 0) > flask_restx_version:
                    import flask
                    if not hasattr(flask.helpers, func_name):
                        setattr(flask.helpers, func_name, _endpoint_from_view_func)
        except ImportError:
            print(f"skipping monkey patch of {func_name}")

Original Author Ryu_CZ Of This Content

Solution 4

I had a similar issue I just solved (or still trying to solve) here
Funny think is that I cannot get my server run without that “monkey” solution even with my flask_restful beign at 0.3.9.
I am not sure what is the issue, thank you for this thread though.

Original Author user14819924 Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment