Python Requests POST not working
10,842
Actually the issue was due to SSL , if your server is using https
method then you need to add following line in requests.post
r = requests.post(api_url, data = {"var 1":"value", "var 2":"value"}, verify=True)
Also make sure your api_url includes https
not http
I have written a small function for that
def get_base_url(request):
host = get_host(request)
if request.is_secure():
return '{0}{1}/{2}'.format('https://', host, 'url')
else:
return '{0}{1}/{2}'.format('http://', host, 'url')
Author by
user5594493
Updated on June 05, 2022Comments
-
user5594493 almost 2 years
I am using python requests module for calling API's. Everything was working fine until I pushed my code to AWS. Even on AWS it is working if I am working on dev server i.e.,
ec2.####.amazon.com:8000
.Here is my code :
r = requests.post(api_url, data = {"var 1":"value", "var 2":"value"})
My API url not allowed
GET
method so in response I am getting error thatGET
method not allowed which meansrequests.post
is reads asget
Any idea what’s wrong here.