AttributeError: у объекта «builtin_function_or_method» нет атрибута «translate» - PullRequest
1 голос
/ 19 марта 2019

Я использую Ubuntu в качестве ОС, pymysql, flask, sqlalchemy frameworks.Затем я делаю запрос GET, у меня есть эта ошибка:

  File "/srv/MSH/venv/local/lib/python2.7/site-packages/pymysql/converters.py", line 73, in _escape_unicode
    return value.translate(_escape_table)
AttributeError: 'builtin_function_or_method' object has no attribute 'translate'

Мой код route.py:

@app.route('/device/<dev_id>/<name>/<dev_type>/<state>', methods=['GET'])
def device(dev_id, state, dev_type, name):
    # This function communicates with device
    dev_state = 0
    device = Devices.query.filter_by(dev_id=id).first()
    # Check state
    if state == "0":
        state = False
    if state == "1":
        state = True
    if device is None:
        # if we don't know device write to database
        dev = Devices(dev_id=dev_id, type=dev_type, prev_state=state, name=name)
        db.session.add(dev)
        db.session.commit()
        return "hi"
    else:
        # Write data to database and return wanted state
        device.prev_state = state
        if device.state:
            dev_state = 1
        if not device.state:
            dev_state = 0
        db.session.commit()
        return str(dev_state)
...