POST-запросы, работающие с POSTMAN, но ошибка OpenSSL с Python - PullRequest
0 голосов
/ 01 ноября 2019

Я пытаюсь получить токен через API.

Когда я использую POSTMAN, мне нужно отключить проверку SSL-сертификата в настройках, чтобы он работал. С Python3.6 и запросами 2.22 у меня ошибка OpenSSL, это мой код

import requests

access_point = "https://xxxxxxxxxxx/token"

grant_type = (
    "grant_type=password&username=my_username&password=my_password"
)

headers = {
    "Content-Type": "application/x-www-form-urlencoded",
    "Accept": "application/json",
    "Cache-Control": "no-cache",
    "Host": "host_name",
    "Cache-control": "no-cache",
}

response = requests.post(
    access_point,
    data=grant_type,
    headers=headers,
    verify=False
)

Я должен получить что-то вроде

{
    "access_token": "qUSUEBm8xLe_IX34x2bTWgKDTeWWPwLQEnCVLoTUexDUz_4eGrFKWPlxoWJtzaT6KVZPqEUe9l1xyhhZLwu1vuzmb5a49uWUFcFMay6x_OFPgUHhYrLZYqsIKh6JJI2xfrf-ha_BYN9PRDYSHrC26JX3grACiXWhb872kdajEzfAQLMQVRvUjligzUoHqE6wdYZWNMtPg1PgWrUsS8bpG5nyL3aq5_i9WuHHPIjCXyAwq3OuW6yJy1lZTSRZ5haYS2Rj5kP9TIaYqOrzBWmZEJSEukkiyOsG_1",
    "token_type": "bearer",
    "expires_in": 86399
}

вместо этого у меня Open SSL ERROR

Traceback (most recent call last):
  File "D:\APP\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 485, in wrap_socket
    cnx.do_handshake()
  File "D:\APP\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1638, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "D:\APP\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1370, in _raise_ssl_error
    raise SysCallError(errno, errorcode.get(errno))
OpenSSL.SSL.SysCallError: (10060, 'WSAETIMEDOUT')

Когда я использую команду curl, у меня есть

*   Trying 192.99.45.211...
* TCP_NODELAY set
* Connected to host_name (192.99.45.211) port 443 (#0)
* schannel: SSL/TLS connection with host_name port 443 (step 1/3)
* schannel: checking server certificate revocation
* schannel: ALPN, offering http/1.1
* schannel: sending initial handshake data: sending 204 bytes...
* schannel: sent initial handshake data: sent 204 bytes
* schannel: SSL/TLS connection with host_name port 443 (step 2/3)
* schannel: failed to receive handshake, need more data
* schannel: SSL/TLS connection with host_name port 443 (step 2/3)
* schannel: encrypted data got 3559
* schannel: encrypted data buffer: offset 3559 length 4096
* schannel: sending next handshake data: sending 214 bytes...
* schannel: SSL/TLS connection with host_name port 443 (step 2/3)
* schannel: failed to receive handshake, SSL/TLS connection failed
* Closing connection 0
* schannel: shutting down SSL/TLS connection with host_name port 443
* Send failure: Connection was reset
* schannel: failed to send close msg: Failed sending data to the peer (bytes written: -1)
* schannel: clear security context handle
curl: (35) schannel: failed to receive handshake, SSL/TLS connection failed

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...