AJAX调用如下所示:json_dictionary = {url : url, profile_dict: dictionary, final_dict : final_dictionary}
$.ajax({
url: "https://localhost:8090/add_profile_data",
type: "POST",
data: JSON.stringify(json_dictionary),
contentType:'application/json',
success:function() {
console.log('added profile data')
}
})
客户端如下所示:
^{pr2}$
这样就可以了,打印的结果是
另外,当我打印data对象时,所有东西都在那里。在
但是,当我尝试:@app.route('/add_profile_data', methods=['POST', 'GET', 'OPTIONS'])
def add():
data = request.json
print(data.keys())
我得到一个错误:AttributeError: 'NoneType' object has no attribute 'keys'
我不明白为什么会这样?有什么想法吗?在
更新:
将服务器更改为这个,现在看到NoneType为{}
服务器:@app.route('/add_profile_data', methods=['POST', 'GET', 'OPTIONS'])
def add():
data = request.json
print(type(data))
print(data.keys())
回应:
127.0.0.1 - - [04/Jan/2017 09:13:47] "OPTIONS /add_profile_data HTTP/1.1" 500 -
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/flask/app.py", line 2000, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1991, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Library/Python/2.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/Library/Python/2.7/site-packages/flask/app.py", line 1567, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Python/2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Library/Python/2.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/Library/Python/2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/Library/Python/2.7/site-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/morganallen/Dropbox/Coding_Projects/Prediction_Server/prediction_v2.py", line 172, in add
print(data.keys())
AttributeError: 'NoneType' object has no attribute 'keys'
为什么我看到{}?在