我正在嘗試在 python 中構建一個 Flask API,它以散列版本回傳我發送給 API 的文本。但是在散列時,我收到以下錯誤:“TypeError: ‘str’ object is not callable”
這是我的代碼:
from flask import Flask, request
from flask_restful import Api, Resource
import hashlib
app = Flask(__name__)
api = Api(app)
class hashing(Resource):
def get(self, text):
hash = hashlib.sha256(text('utf-8'))
text_hashed = hash.hexdigest()
return {"data":text_hashed}
api.add_resource(hashing, "/hash/<text>")
if __name__ == "__main__":
app.run(debug=True)
uj5u.com熱心網友回復:
text是傳遞給hashing方法的實際字串。我猜你是想呼叫encode它,而不是將它用作函式:
hash = hashlib.sha256(text.encode('utf-8'))
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/329049.html
