Reputation: 9
I have been trying to access a flask based python server inside my application using the following code:
baseURL = 'http://' + IP_Add_Server + ":" + PORT
postURL = baseURL + '/new-user'
data = {'username': user_id.get(),'password': password.get()}
r = requests.post(url=postURL, data=data)
The server side code is as follows:
@flask_app.route('/new-user', methods = ['POST'])
def adduser():
if request.method == 'PUT':
ID = request.form['username']
Pswd = request.form['password']
return Response(myDB.add_new_user(ID, Pswd))
else:
return Response('Wrong method', mimetype = 'text/plain')
The response I get for the same is 405. I tried using params
instead of data
but that didn't solve the problem.
Can someone suggest what the problem might be?
Upvotes: 0
Views: 585
Reputation: 15732
It looks like your server is expecting a PUT request, not a POST.
You can fix the issue by either making a PUT request with requests.put
or changing the server to accept POST with if request.method == 'POST':
Upvotes: 1