OSX proxy settings are completely ignored - python

I am trying to set up my own proxy server in python (the code, running on port 9090) but when I change the configuration on my mac it seems like those configuration are completely ignored
The configurations:
(I of curse hit save and apply)
I also checked and my VPN is not connected...
The really odd thing is that I can even change the Web Proxy Server ip to be invalid things and still hit save and apply:
And of curse these configurations are also ignored
No help from apple forums either

Turns out this is a bug in some OSX versions. Apple fixed this bug in Mojave v10.14.6 so updating to this version fixes the problem.

Related

My code raises "httpx.connecttimeout: timed out" exception

Today I was prepairing my project to start on Debian11 VPS server. I'm near level to Junior Python Developer and I don't have any ideas what to do with that. Actually, you could say that I'm just stupid, but my code is working on my Windows Laptop. And exception raises only on Debian server. Thanks for your help!
linux error statement
I tried to change active proxy in my code, but it's still doesn't work on debian and still works on Win
-_-

Django: ERR_CONNECTION_REFUSED

I'm actually learning to use the Django framework with PostgreSQL with Docker and docker-compose.
Regularly, when I make a mistake (for example a syntax error in the views.py file), I cannot reach my Django app anymore trough my web browser.
Firefox tells me:
Unable to connect
Firefox can't establish a connection to the server at localhost:8000
Chrome tells me:
This site can’t be reached
localhost refused to connect.
ERR_CONNECTION_REFUSED
I had this several times and I always managed to find the error in my code, to correct it and then everything went well again.
Currently, my code is working fine. But if I encounter this again (and this happens very often), I would like to be able to find the error quickly by myself.
So here is my question:
How can I see which file at which line contains the error ?
I would like to have a correct error message telling me what went wrong instead of that annoying ERR_CONNECTION_REFUSED browser page over and over.
I hope I explained my issue well because I struggled to describe it to Google.
Thanks a lot in advance. :)
FYI:
Ubuntu 18.04.3 LTS Bionic (window manager i3wm)
Docker 19.03.4
docker-compose 1.17.1
python 3.7 (docker image)
Django 2.2.6 (inside the python 3.7 image)
PostgreSQL 12.0 (docker image)
Visual Studio Code 1.39.2
I finally found a solution.
I had the bad habit to run my docker-compose in detached mode.
When attached, the syntax errors are shown directly from the terminal when de container is stopped.
I also added a script where I run my server in a loop. This way, the server will relaunch automatically over and over until I correct the error. I don't have to restart my Django server manually.
Thank you for helping me anyway.

Local matplotlib display in PyCharm with remote ssh interpreter from Google Cloud Platform's Compute Engine

I am currently running Python 3.5 scripts on two VM instances on GCP from a local PyCharm session running on my Mac (see below for detailed environment specifications).
I have two different projects in GCP which look similar. I reviewed their setup with our cloud admin and we can't see any major difference, at least any trivial one. I created two Deep Learning images on GCP using the following cloud SDK command line, one within each project:
export PROJECT=[MY_PROJECT_NAME]
export INSTANCE_ROOT=$USER-vm
export ZONE=europe-west4-a
export IMAGE_FAMILY=tf-latest-gpu
export INSTANCE_TYPE=n1-highmem-8
export GPU_TYPE=v100
export GPU_COUNT=1
export INSTANCE_NAME=$INSTANCE_ROOT-$GPU_TYPE-$GPU_COUNT
gcloud compute instances create $INSTANCE_NAME \
--zone=$ZONE \
--image-family=$IMAGE_FAMILY \
--image-project=deeplearning-platform-release \
--maintenance-policy=TERMINATE \
--accelerator=type=nvidia-tesla-$GPU_TYPE,count=$GPU_COUNT \
--machine-type=$INSTANCE_TYPE \
--boot-disk-size=200GB \
--metadata=install-nvidia-driver=True \
--scopes=storage-rw
Both images are completely similar.
I configured two remote ssh interpreters in PyCharm and deployed my Python code on both virtual machines. Everything is absolutely similar in terms of VM instance configuration (OS, Python version / libs, source code, etc.) and PyCharm remote interpreter configuration.
In both cases, the ssh ingress connection to the instance (on port 22) works pretty well.
Yet, when calling plt.show() to display images using matplotlib, the images get displayed in one setup but not in the other one.
This is not a matter of setting the proper ssh configuration (-X option on the command line, X11Forwarding, etc.). I already checked that, and anyway one of my VMs does a pretty good job of displaying my images within this configuration.
I debugged the execution and discovered that PyCharm automatically handles X display by implementing its own matplotlib FigureCanvas. When in remote ssh, the show() function actually opens a socket on the defined host (i.e. my local Mac) and sends the buffer to be displayed:
sock = socket.socket()
sock.connect((HOST, PORT))
[..]
sock.send(buffer)
This is precisely where my two configurations diverge:
The one working tries to connect on localhost:53725 and succeeds:
<socket.socket fd=28, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 42316), raddr=('127.0.0.1', 53725)>
The one failing tries to connect on localhost:53725 as well but gets an exception.
My strongest assumption is that some network configuration in the two GCP projects differs somehow and prevents the connection on localhost:53725 for the second one.
However, beyond that I have no idea what might happen and/or how to fix it.
Any idea / suggestion will be appreciated.
Thanks,
Laurent
--
Detailed environment specifications:
PyCharm 2018.2.4 (Professional Edition)
Build #PY-182.4505.26, built on September 19, 2018
Licensed to PyCharm Evaluator
Expiration date: October 27, 2018
JRE: 1.8.0_152-release-1248-b8 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14
Ok. It seems to be a bug and I found a workaround.
I share it as it might save hours of troubleshooting and debugging to anyone stumbling on the same problem.
The problem actually occurs when you remain in the same PyCharm session and switch from one interpreter to the other one.
If you quit PyCharm and start it again, the local display will work with either of the interpreters / VMs you run first. Then, if you switch to the second one it fails.
Everything looks as if there were some kind of lock set on the port or anywhere else by PyCharm which prevents you from switching seamlessly from one interpreter to another.
I'll share these insights with the PyCharm support team. BTW, other than that, this local display feature with remote interpreters is awesome and works just fine.

pydev remote debug path

I want to use eclipse, pydev to remote debug my python script. Python script is on a remote Ubuntu server, and Eclispe/pydev is running on my Windows 7 machine.
I followed every step according to this one.
http://pydev.org/manual_adv_remote_debugger.html
The problem is in the last step of configuring path in pydevd_file_utils.py on server, it does not recognize the change. This is what I changed:
PATHS_FROM_ECLIPSE_TO_PYTHON = [(r'c:\EZ_Green\plugins', r'/home/jiechao/EZ_Green/plugins')]
When I run the script, it gives me such error.
pydev debugger: warning: trying to add breakpoint to file that does not exist: /home/jiechao/EZ_Green/plugins/D:/EZ Green/backend/getData.py (will have no effect)
Seems the change does not apply, has anyone done this before or have any ideas?
Thanks a lot
-----------------update 1--------------
So I solve the previous problem and now here is the new problem.
This is the output of program, and it seems the path configuration is correct.
Debug Server at port: 5678
pydev debugger: replacing to server: D:\EZ Green\Product\EZ_Green\plugins\test.py
pydev debugger: sent to server: /home/jiechao/EZ_Green/plugins\test.py
pydev debugger: replacing to client: /home/jiechao/EZ_Green/plugins/test.py
pydev debugger: sent to client: D:\EZ Green\Product\EZ_Green\plugins/test.py
But eclipse does not stop at the breakpoint, not even at pydevd.settrace()
I have no idea why it does not stop.
When I use remote debug on local machine, it works pretty well. When I want to debug on a remote server machine, it does not work. I don't know what's the problem.
------------------update 2---------------------
Problem solved. The script on my client and server turns out to be a little different. So I did not see the breakpoint it stopped.
I am so stupid!
Thanks anyway.
Even though it is possibly not the exact approach you may expect,
one option is to start the Unittest from the command line and attach the debugger by RemoteDebugServer via 'pydevd.py'.
This is now a fully automated option of ePyUnit which includes the automation of remote debugging with PyDev and Eclipse by 'pydevd.py'. This works seamlessly for 'subprocesses' as well as independently started command line processes.
The hostame and the port number could be varied as required, default is
localhost:5678.
See:
https://pypi.python.org/pypi/epyunit
https://pythonhosted.org/epyunit/
For basics of remote debugging:
http://www.pydev.org/manual_adv_remote_debugger.html
Also enhanced unittest integration into PyUnit.
Comments and fixes are welcome.
Have fun.

Which registry / environment (or other) settings does urllib2.urlopen use to determine proxy settings?

Following on from this question: What is causing urllib2.urlopen() to connect via proxy?
I'd like to know which operating system & environmental settings can affect urllib2.urlopen?
For example, I've noticed that on some machines within our very large corporation urllib2.urlopen insists on connecting via a proxy. This is a problem because the resources our application needs to connect to are on the local network, and so adding the proxy to the mix causes authentication problems.
I'm using Windows 32bit XP / Python 2.4.4
You can see the exact code, but as the docs say the registry section is Internet Settings:
HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings

Categories

Resources