Python 3.51 Requests causes Proxy Error

12,457

Maybe try the following:

import requests

proxies = {
  'http': 'http://10.123.123.10:8080',
  'https': '10.123.123.10:8080',
}

response = requests.post('https://app.informaticaondemand.com/ma/api/v2/user/login', headers=genheaders, data=data, proxies=proxies)

Link to requests proxy documentation: http://docs.python-requests.org/en/master/user/advanced/#proxies

Share:
12,457
mroshaw
Author by

mroshaw

Updated on June 30, 2022

Comments

  • mroshaw
    mroshaw almost 2 years

    I'm trying to consume the Informatica Cloud REST API using Python (3.51) Requests (requests package version is 2.10.0):

    import requests
    
    username='myuser'
    password='mypassword'
    
    genheaders = {
        'Content-Type': 'application/json',
    }
    
    data = '{"@type":"login","username":"' + username + '","password":"' + password +'"}'
    response = requests.post('https://app.informaticaondemand.com/ma/api/v2/user/login', headers=genheaders, data=data)
    

    On my local machine, all works splendidly. However, on my TEST server, I get the following error:

    HTTPSConnectionPool(host='app.informaticaondemand.com', port=443): Max retries exceeded with url: /ma/api/v2/user/login (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',)))

    Annoyingly, curl works fine on the server machine:

    curl -H "Content -Type: application/json" -X POST --data @Login.txt   https://app.informaticaondemand.com/ma/api/v2/user/login -k
    

    Where login.txt has:

    { "@type": "login","username":"myuser", "password":"mypassword"}

    If I don't use the -k switch, I get:

    curl: (60) SSL certificate problem, verify that the CA cert is OK. Details: Error:14090086:SSLroutines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed More details here: http://curl.haxx.se/docs/sslcerts.html

    All is fine with the -k switch.

    I've tried setting the proxy via environment variables, prior to executing Python.exe:

    set HTTP_PROXY=10.123.123.10:8080
    set HTTPS_PROXY=10.123.123.10:8080
    

    But the results are the same.

    Any ideas on what to try next?