Python Request.Post to API not working

时间:2017-08-30 20:33:40

标签: python python-requests

I am trying to send a simple POST to an api.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  if ([segue.identifier isEqualToString:@"showRecipePhoto"]) {
    RecipeViewController *destViewController = segue.destinationViewController;
    destViewController.recipeImageName = selectedRecipeImageName
  }
}

I keep getting status code 401.

Same steps Works fine in POSTMAN.

enter image description here

enter image description here

Any Ideas/pointers ?

3 个答案:

答案 0 :(得分:2)

Post data in raw format.

fa

FWIW, you can click on Code below the Save button on the top right corner of Postman to view code in a couple of languages for your request.

答案 1 :(得分:1)

It will only works if the API accepts also JSON body. Otherwise you can use the @Oluwafemi Sule's answer.

whatsapp

答案 2 :(得分:1)

这段代码对我有用。

import requests
from requests_ntlm import HttpNtlmAuth
payload = "username=;password=;"
s= requests.post(
        "http://someapi/v1/auth", 
        headers={"content-type":"application/x-www-form-urlencoded"},
        data = payload, 
        auth=HttpNtlmAuth('',''))
print s.status_code