1

Implementing flask with brownie, to automate the the code create_collectible when hitting a button. The import simple collectible is from this tutorial:

https://youtu.be/ZH_7nEIJDUY

Links:

https://www.youtube.com/watch?v=sOVxkPvAHjI&t=776s https://flask.palletsprojects.com/en/2.0.x/tutorial/views/

File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 256, in locate_app
    __import__(module_name)
  File "/Users/work/Documents/OpenvinoNFT/app/api/api.py", line 2, in <module>
    from create_collectible import main, nftcode
  File "/Users/work/Documents/OpenvinoNFT/app/api/create_collectible.py", line 4, in <module>
    from brownie import SimpleCollectible, account, network, config
ImportError: cannot import name 'SimpleCollectible' from 'brownie' (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/brownie/__init__.py)

Traceback (most recent call last)
File "/Users/work/Documents/OpenvinoNFT/app/api/api.py", line 2, in <module>
from create_collectible import main, nftcode
File "/Users/work/Documents/OpenvinoNFT/app/api/create_collectible.py", line 4, in <module>
from brownie import SimpleCollectible, account, network, config
During handling of the above exception, another exception occurred:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 359, in __call__
rv = self._load_unlocked()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 346, in _load_unlocked
self._app = rv = self.loader()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 402, in load_app
app = locate_app(self, import_name, name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 261, in locate_app
raise NoAppException(
flask.cli.NoAppException: While importing 'api', an ImportError was raised:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 256, in locate_app
__import__(module_name)
File "/Users/work/Documents/OpenvinoNFT/app/api/api.py", line 2, in <module>
from create_collectible import main, nftcode
File "/Users/work/Documents/OpenvinoNFT/app/api/create_collectible.py", line 4, in <module>
from brownie import SimpleCollectible, account, network, config
ImportError: cannot import name 'SimpleCollectible' from 'brownie' (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/brownie/__init__.py)

The SimpleCollectible is a contract in solidity created by myself. If I run the code without flask, it runs!! It’s not that!

1
  • Can you add the solidity code? Sep 27, 2021 at 21:19

1 Answer 1

0

I managed to solve this by doing the next:

In my flask app i added:

os.system("brownie run scripts/simple_collectible/create_collectible.py  --network rinkeby")

under my @app.route on flask.

The problem was that the code was running on the python CLI, and not in the Brownie CLI like it was supposed to.

It might not be the best way of doing it, but it works. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.