Wanhenri / Projeto-ERP

0 stars 0 forks source link

ERROR connection with DB #1

Closed Wanhenri closed 4 years ago

Wanhenri commented 4 years ago

An error occurred while connecting the database function to the flask.

from database.ConexaoSQL_v2 import Vendor
from database.ConexaoSQL_v2 import db
from flask_restful import Resource

def Vendor_item(name,cnpj,city):
    vendor = Vendor(name='product', cnpj='cnpj', city='city')
    db.session.add(vendor)
    db.session.commit()

class Vendor_item(Resource):
    def get(self):
        return {
            'status': 200,
            'response': "Funciona Vendor_item"
        }

    def post(self):
        Vendor_item_reports = Vendor_item(name,cnpj,city)
        return Vendor_item_reports

ERROR

    return self.dispatch_request(*args, **kwargs)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask_restful\__init__.py", line 583, in dispatch_request
    resp = meth(*args, **kwargs)
  File "H:\programas_github\Projeto-ERP\api\database\add_vendor_database.py", line 22, in post
    Vendor_item_reports = Vendor_item(name,cnpj,city)
NameError: name 'name' is not defined
Wanhenri commented 4 years ago

other error:

C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask_sqlalchemy\__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.
  warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.')
 * Debugger is active!
 * Debugger PIN: 276-203-085
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
##################
wanderson
123123123
teste
##################
ESTA?
127.0.0.1 - - [10/Jun/2020 21:37:38] "←[35m←[1mPOST /vendor_item HTTP/1.1←[0m" 500 -
Traceback (most recent call last):
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask\app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask\app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask_restful\__init__.py", line 272, in error_router
    return original_handler(e)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask\app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask\_compat.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask\app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask_restful\__init__.py", line 272, in error_router
    return original_handler(e)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask\_compat.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask\app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask_restful\__init__.py", line 472, in wrapper
    return self.make_response(data, code, headers=headers)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask_restful\__init__.py", line 501, in make_response
    resp = self.representations[mediatype](data, *args, **kwargs)
  File "C:\Users\Wanderson\.virtualenvs\api-OxVh_rFM\lib\site-packages\flask_restful\representations\json.py", line 21, in output_json
    dumped = dumps(data, **settings) + "\n"
  File "c:\users\wanderson\appdata\local\programs\python\python37\lib\json\__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "c:\users\wanderson\appdata\local\programs\python\python37\lib\json\encoder.py", line 201, in encode
    chunks = list(chunks)
  File "c:\users\wanderson\appdata\local\programs\python\python37\lib\json\encoder.py", line 438, in _iterencode
    o = _default(o)
  File "c:\users\wanderson\appdata\local\programs\python\python37\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Vendor is not JSON serializable
Wanhenri commented 4 years ago

Fixed error add_vendor_database

The class had the same name as the function. note: correct in the other function in /add_product_database.py

Wanhenri commented 4 years ago

This bug was corrected in: /add_product_database.py