REST API Call via Python requests does not work on VPN - python

I am calling a REST API to Informatica from POSTMAN and Python (requests library) and find the behavior quite funny.
When I am on VPN I can only make a successful call from POSTMAN, however if I switch VPN off both Python and POSTMAN calls work perfectly.
Python script generated automatically by POSTMAN.
Error:
ConnectionError: HTTPSConnectionPool(host='use4-mdm.dm-us.informaticacloud.com', port=443): Max retries exceeded with url: /rdm-service/external/v2/export (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002393AB297C0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
Any ideas what the reason might be?
UPD
To make my question more clear:
This is a corporate VPN on work laptop
My system does not have *_PROXY variables
No default proxy in requests library
import requests
session = requests.Session()
session.proxies
>>> {}
http.client library - same result
Settings in POSTMAN are in screenshot below

you may want to have a look at the "proxies" parameter of python requests :)

Related

Snowflake AWS Privatelink - Python Connector Error Max retries exceeded with url: /session/v1/login-request?

we recently configured aws privatelink to snowflake account and updated python connector (v.1.8.0) properties to use privatelink URL.
Connection keeps failing with below error.
Failed to execute request: HTTPSConnectionPool(host='testaccount.us-west-2.privatelink.snowflakecomputing.com', port=443): Max retries exceeded with url: /session/v1/login-request?warehouse=TEST_WH&request_id=12345&request_guid=f5467 (Caused by ProtocolError('Connection aborted.', BadStatusLine("''",)))
Has anyone encountered this issue when using AWS privatelink?
Any inputs would be greatly appreciated.
On the host where you are running python, if linux or OSX, can you run:
curl -v -L https://testaccount.us-west-2.privatelink.snowflakecomputing.com:443
Do you know if you have a proxy in place allowing your Web URL to work?
https://www.digitalcitizen.life/how-set-proxy-server-all-major-internet-browsers-windows
That error is because the python code is unable to reach the privatelink URL. Either it's on a host that is blocked, there is a firewall blocking, or you require a proxy.

Can connect via Postman but not via python script

I am helping my client to solve a problem. He tries to call my API but is unsuccessful.
Situation:
my API is accessible via postman and the browser (swagger). It works.
On the same computer via a python script I cannot access to the API
error:
Caused by NewCOnnectionError('<urllib3.connection.HTTPConnection object at 0x000001310A6F5C0>:
Failed to establish a new connection: [Errno 11001] getaddrinfo failed')
If I try a very simple script
import requests
r = requests.get('http://google.com')
I get the same error.
I assume there some problem with firewall/proxy but why does Postman work?
In which direction can I direct my client to solve problem?
I also tried ping and it doesn't work either:
$ ping www.google.com
Ping request could not found host www.google.com. Pleas check the name and try again.

Docker connection to localhost refused

On linux I started a server at localhost:8090. From a docker container through Jupyter notebook I am trying to send a PUT request to the localhost server. GET requests seem to work just fine from the docker container but PUT requests show the following error.
ConnectionError: HTTPConnectionPool(host='localhost', port=8090): Max retries exceeded with url: /xxxxx/xxxxx/xxxxx (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b9ee1d978>: Failed to establish a new connection: [Errno 111] Connection refused'))
Using curl from local terminal, I am able to send a PUT request without any problem.
The PUT requests seemed to be working in first 1-2 hours (even from the docker container) but then the error started appearing. Is it possible that there are some connections still alive and the server cannot accept any more? Restarting the server and my machine did not fix the problem.

Passing all Python's traffic through proxy using PyCharm

I am working in a corporate environment with a proxy (with user/passs). I use PyCharm on a Windows machine and Python 3.6.
Based on this post:
How to pass all Python's traffics through a http proxy? I managed to write my python script that connects to the web.
Unfortunately I had to reinstall Pycharm and create a new python project. Now I run the same script that connects to the web but receive the following error message (simply trying to connect to google.com):
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),))
This is my code:
import os
proxy = 'http://user:password#proxyname:port'
os.environ['http_proxy'] = proxy
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy
import requests
r = requests.get('https://www.google.com')
print(r.text)
If I change the line
r = requests.get('https://www.google.com')
to this:
r = requests.get('https://www.google.com', verify=False)
it works but I receive the warning:
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised.
Executing the code on another machine without proxy This issue doesn't appear at all.
I added google's certificate in PyCharm's settings (Settings -> Tools -> Server Certificates) and selected "Accept non-trusted certificates automatically". But nothing changes, same error messages.
Is there any further settings I can do in PyCharm/Python to solve that issue?

Uwsgi Application cannot connect https with proxy

My application running with Uwsgi on the server that using proxy. The server proxy is in one network. But whenever the application trying to make https request (443), it raises an error like it cannot connect to internet.
HTTPSConnectionPool(host='api.blabla.com', port=443): Max retries exceeded with url: /endpoint/v2/checkout_url (Caused by NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))
for proxy, I'm using squid for http and https. and for the client side, the proxy has been setup system-wide.
Kindly need advice from this issue. thanks in advance.

Categories

Resources