0

In an isolated network at the enterprise, was deployed API server with a self-signed certificate. Access to API-server via Postman works. But if I try to connect to server via Python, then the body request seems like empty, but i'm not sure

import requests
import json
import http.client

from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)

url = "https://{...}:{...}/GetData"


payload = json.dumps({
    "Start": 60,
    "Count": 2
})

headers = {
    'Host': '...',       
    'X-Forwarded-Proto': 'https',
    'Connection': 'keep-alive',
    'Content-Length': str(len(payload)),
    'Content-Type': 'application/json',
    'Accept': '*/*',
    'Accept-Encoding': 'gzip, deflate, br'
}

response = requests.post(
        url,
        headers=headers,
        json=payload,
        verify=False
        )
print(response.text)

P.S. I tried to use data instead json but it didn't help. Api-server don't use authentication for this url.

ilka.xd
  • 11
  • 1
  • Did you try to generate the python code in postman? The code generator has two different python options in the Code snippet tab and they both look different from your example. response = requests.request("POST", url, headers=headers, data=payload). It's unclear to me if this example uses Python 2 or 3. Maybe try with both. –  Sep 12 '22 at 18:44
  • 1
    Yes, i used generated code from postman. It not work too. And code from postman don't solve the problem with self-signed certificate (need use requests.request(..., verify=False) and for [http.client](https://stackoverflow.com/questions/51390968/python-ssl-certificate-verify-error)). I think, postman use python3, becouse it generates ```print(some_text)``` not ```print some_text```. Thanks for attention to my problem – ilka.xd Sep 13 '22 at 08:07

0 Answers0