当我尝试访问http://localhost:5000/soap/someservice时收到406不可接受
API错误:根据请求中发送的接受标头,由请求标识的资源仅能够生成具有不可接受的内容特征的响应实体。受支持的实体是text / html。
这是服务器端的摘录
from flask import Flask, jsonify
from flask_accept import accept
app = Flask(__name__)
@app.route('/soap/someservice')
@accept('text/html')
def hello_world():
return 'Hello World!'
我在客户端尝试的操作
from suds.client import Client
url = 'http://localhost:5000/soap/someservice?wsdl'
client = Client(url)
406 not acceptable
import requests
r=requests.get("http://localhost:5000/soap/someservice", headers={"content-type":"text"})
print(r)
406 not acceptable
所有解决方案都会给相同的错误任何提示吗?
答案 0 :(得分:1)
您已指定
@accept('text/html')
在Flask端点中,但您未在请求中提供指定text/html
的{{3}}。比较运行Flask应用程序,但使用以下方法:
In [3]: import requests
...: r=requests.get("http://localhost:5000/soap/someservice",
headers={"Accept":"text/html"})
...: print(r)
...:
<Response [200]>