Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

*Python* 406 not acceptable

I am getting 406 not acceptable when i try to access http://localhost:5000/soap/someservice

API Error: The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request. Supported entities are text/html.

Here is a snippet from the server side

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!'

What i tried on the client side:

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

All solutions give the same error any hints ?

like image 940
Star Avatar asked Dec 15 '25 14:12

Star


1 Answers

You have specified

@accept('text/html')

In the Flask endpoint, but you have not provided an Accept Header specifying text/html in your request. Compare running your Flask app, but using:

In [3]: import requests
   ...: r=requests.get("http://localhost:5000/soap/someservice", 
                       headers={"Accept":"text/html"})
   ...: print(r)
   ...:
<Response [200]>
like image 117
bigreddot Avatar answered Dec 19 '25 07:12

bigreddot