TypeError TypeError: 'dict' object is not callable , post request
TypeError TypeError: 'dict' object is not callable , post request
我正在尝试从 python 函数调用我自己的 Post API
,api 方面没有问题,它工作正常,但是当我尝试调用 POST
API from Python function
下面是我的代码
@app.route('/dhiru_post', methods=['GET'])
def dhiru_post():
url = "https://www.mydomainamehere.com/api_new/"
payload = {"number": 12524,
"api_type": "news_listing",
"slug": "life-mantra",
"start": 0,
"end": 10}
response_decoded_json = requests.post(url, data=payload)
response_json = response_decoded_json.json()
return response_json
Note: https://www.mydomainamehere.com/api_new/ this is not the exact
url, please ignore .
错误:
打开这个 url :
https://dhiru-ai-quantomsoftech.herokuapp.com/webhook_dhiru
TypeError
TypeError: 'dict' object is not callable
Traceback (most recent call last)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1577, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/wrappers/base_response.py", line 269, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/test.py", line 1119, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'dict' object is not callable
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.
You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:
dump() shows all variables in the frame
dump(obj) dumps all that's known about the object
您可以按如下方式修改处理程序:
from flask import jsonify
@app.route('/dhiru_post', methods=['GET'])
def dhiru_post():
url = "https://www.mydomainamehere.com/api_new/"
payload = {
"number": 12524,
"api_type": "news_listing",
"slug": "life-mantra",
"start": 0,
"end": 10
}
response = requests.post(url, data=payload)
return jsonify(response.json())
所以基本上你需要 return 一个响应而不是一个字典,jsonify
会为你做到这一点:设置正确的 content-type 并转换 response.json()
字典串起来并将其用作内容。
我正在尝试从 python 函数调用我自己的 Post API
,api 方面没有问题,它工作正常,但是当我尝试调用 POST
API from Python function
下面是我的代码
@app.route('/dhiru_post', methods=['GET'])
def dhiru_post():
url = "https://www.mydomainamehere.com/api_new/"
payload = {"number": 12524,
"api_type": "news_listing",
"slug": "life-mantra",
"start": 0,
"end": 10}
response_decoded_json = requests.post(url, data=payload)
response_json = response_decoded_json.json()
return response_json
Note: https://www.mydomainamehere.com/api_new/ this is not the exact url, please ignore .
错误: 打开这个 url : https://dhiru-ai-quantomsoftech.herokuapp.com/webhook_dhiru
TypeError
TypeError: 'dict' object is not callable
Traceback (most recent call last)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1577, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/wrappers/base_response.py", line 269, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/test.py", line 1119, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'dict' object is not callable
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.
You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:
dump() shows all variables in the frame
dump(obj) dumps all that's known about the object
您可以按如下方式修改处理程序:
from flask import jsonify
@app.route('/dhiru_post', methods=['GET'])
def dhiru_post():
url = "https://www.mydomainamehere.com/api_new/"
payload = {
"number": 12524,
"api_type": "news_listing",
"slug": "life-mantra",
"start": 0,
"end": 10
}
response = requests.post(url, data=payload)
return jsonify(response.json())
所以基本上你需要 return 一个响应而不是一个字典,jsonify
会为你做到这一点:设置正确的 content-type 并转换 response.json()
字典串起来并将其用作内容。