【发布时间】:2019-06-13 04:58:24
【问题描述】:
我正在尝试从 python 函数调用我自己的Post API,在 api 方面没有问题,它工作正常,但是当我尝试调用 POSTAPI 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
注意:https://www.mydomainamehere.com/api_new/ 这不是确切的 网址,请忽略。
错误: 打开这个网址: 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
【问题讨论】:
-
问题是
return response_json。请求成功,请确保支持response_json的类型。 -
@Sraw 我是 python 的初学者,我不知道我将如何解决这个问题,您能否发布一些示例以用于发布请求,其中包含 JSON 输入和 JSON 输出