return http error code for curl in python
Question: 
    status, output = commands.getstatusoutput("curl -k -v --cookie cookie_name 'URL' -o filename")
    

Above is my code , I am trying to return http response code of curl. So i
tried the following option -w %{http_code}

    
    
    status, output = commands.getstatusoutput("curl -k -v --cookie cookie_name -w %{http_code} 'URL' -o filename")
    

When i run it in python script and print status, nothing gets printed. Can
someone please help me with the curl return code? I want to try scenario's
like when username password is wrong to get a status, or when the network host
is not reachable or content not downloaded properly.


Answer: As the other guys suggested, it is better to use HTTP to do a curl call.
[requests](http://docs.python-requests.org/en/latest/) is the easiest way:

    
    
    import requests
    
    data = {
        ...
    }
    r = requests.post(url, data=data)
    print r.content
    

`r.content` contains the response body and if you need the status code just
use `r.status_code`.

