Python Requests Code 141 Error
Question: I'm trying to use requests in python to post a json dictionary to a url. I
need to get a string back from the url but I keep getting a code 141 error
-{"code":141,"error":"Missing a github repository link"}. I'm using this
website(<http://docs.python-requests.org/en/latest/user/quickstart/>) to do
requests.

Any ideas on why I keep getting that error? Code is below.

    
    
    import requests
    import json
    
    payload = { "email" : "jade@gmail.com", "github" : "https://github.com/"}
    headers = {'content-type': 'application/json', "Accept": 'application/json'}
    r = requests.post("http://challenge.code2040.org/api/register", params = payload, headers = headers)
    
    print(r.url)
    print r.text
    

Update: The suggestion worked but now I'm getting
an{"code":141,"error":"success/error was not called"} error when I try to save
the response I recieve from the url into a variable and then post it back to a
different url.

    
    
    #Store the token into a variable
    token = r.text
    
    payload = { "token" : token}
    headers = {'content-type': 'application/json', "Accept": 'application/json'}
    r = requests.post("http://challenge.code2040.org/api/getstring", json = payload, headers = headers)
    
    print r.text
    


Answer: Since you are making a `POST` request and [you need to provide a JSON in the
request body](http://challenge.code2040.org/), use [`json`
argument](http://docs.python-
requests.org/en/latest/api/?highlight=post#requests.post), not `params`:

    
    
    r = requests.post("http://challenge.code2040.org/api/register", 
                      json=payload, 
                      headers=headers)
    

(tested - got back a token)

Note that `json` argument was introduced in [requests
2.4.2](https://github.com/kennethreitz/requests/blob/master/HISTORY.rst#242-2014-10-05).

