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')
Share:
10,842
user5594493
Author by

user5594493

Updated on June 05, 2022

Comments

  • user5594493
    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 that GET method not allowed which means requests.post is reads as get

    Any idea what’s wrong here.