Docker python requests results in DH KEY TOO SMALL error - python

I'm trying to setup a python script that uses the requests library to get data from a website. The script works without issues running in a virtual environment on my windows 10 pc or on a azure vm.
However, when I try to create a docker container using the python:3.6-slim image I get DH_KEY_TOO_SMALL errors. Testing the website on ssllabs.com revealed that it supports weak DH key exchange parameters. What could be causing this error and how can I fix it?

I've managed to fix the issue. The problem was caused by openssl versions. Both my windows 10 pc and ubuntu 18.04 vm run an older version that had no problem connecting to the website. The python docker images contain a newer version of openssl that refused to connect.

Related

Code navigation for remote server in VS code

I have installed visual code in my mac to be able to access code to a remote server. I have installed remote-ssh and python packages for vs code and I have managed to connect remotely to my projects in server. However, my issue is while I can use python code navigation locally, I cannot do it in the server. Any ideas why?
Do I need to do any configuration in the remote server?
Check if the Pylance extension is installed on your remote extensions or not. I used to stick to this problem once so by installing the Pylance my problem was solved.

Python script on EC2 returns wrong signature type error

I'm coding a discord bot in python. Whenever I try to connect to a specific site, on my EC2 instance running Amazon Linux 2, the script returns the following error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientConnectorSSLError: Cannot connect to host secure.site.here:443 ssl:None [[SSL: WRONG_SIGNATURE_TYPE] wrong signature type (_ssl.c:1076)]
(actual url snipped.)
The bot itself is dockerized, running python:3.7.4-slim-buster. The error is not present when built with image python:3.7.4-slim-stretch.
I've also tested the same script built with base image -buster on MacOS and also a GCP Compute Engine instance, both are error free.
What am I missing? Any tips welcome.
First of all I checked the current tls version used by connection to the site. It was 1.2.
I got same error with wget so I understand that problem not in python itself, but somewhere in openssl and system settings.
On Ubuntu 20.04.1 LTS I upgrade openssl from 1.1.1f to 1.1.1g - it solves the issue for me. I followed this manual.

Pycharm, Docker and GUI

So i have downloaded openAI gym into docker. And i am running Pycharm with docker remote interpreter. Everything works fine until the code gets to the rendering part where it crashes. I know that it is caused because Docker does not support GUI.
I tried using x11 but it didnt work.
Any advice ?
Assuming you're on OSX:
Your problem is probably not related with pycharm but more with how docker tries to connect to x11.
Make sure you installed the latest version of xQuartz and allow x11 network clients. Then mount the x11 socket as a volume mount in the docker container.
This blog post has a pretty good explanation on how to do that
https://fredrikaverpil.github.io/2016/07/31/docker-for-mac-and-gui-applications/

Python plotting on remote server using PyCharm

I have started to learn Python and so far my setup has been following - Python 3.5 installation on Win10 64bit local machine with PyCharm as a great IDE. Everything works, matplotlib charts and other visual outputs display fine, debugging works, etc.
Now, I have came across some libraries which works only on Linux. I have set up Ubuntu 16.4 64bit VPS on Digital Ocean, installed Python 3.5. In PyCharm I have set up SFTP connection to remote host. Code running works, debugging works, however, I am not able to bring display output (matplotlib plots,...) to local (Win10) machine. As I am not at all familiar with Linux GUI environments (X11?), after googling I have following questions:
1) Should anything be installed on remote Linux machine? (e.g. x11 client/server/smth?)
2) Should anything be installed on local Win machine? (e.g. Xming?)
3) Should anything be configured on remote Linx machine? (e.g. X11 forwarding)
4) Should anything be configured on local Win machine PyCharm?
5) There are X11 forwarding settings in Putty and some have suggested to use those but I am not sure, should Putty session run in paraller with PyCharm and can that be avoided.
Thanks a lot!
PS - I have installed Jupyter Notebook (and latest Jupyter Lab) on remote machine and it works excellent, however I am still prefering PyCharm as primary IDE with better code completion, debugger and other perks.
Ok, after some more googling I finally managed to get this process working, hope it helps somebody:
1) on remote host (VPS, Ubuntu 16.04) I had to install X11 server, which I did by:
sudo apt-get install xorg
sudo apt-get install openbox
2) On remote host I had to make sure that X11Forwarding is enabled in /etc/ssh/sshd_config
3) On local Win10 machine I had to install Xming server and launch it with default settings.
4) On local Win10 machine I had to configure Putty to use X11 forwarding (Connection-> SSH -> X11 Forwarding) with default settings and keep connection open while running PyCharm (it seems there is no option in PyCharm to enable x11 forwarding, so putty must be running in the background)
5) On remote machine I had to check Display number (echo $DISPLAY) - this can be different for everyone. For me it was localhost:10.0
6) In PyCharm Run configuration -> Environment variables I had to add DISPLAY=localhost:10.0
After all these steps and Putty+Xming running in backgroud, I was able to execute remote code and bring graphic back to my Windows 10 PC!
PS - process is actually slow, I have to wait around 10 seconds before image is brought back to me. I am not sure why or how to speed it up. Might be another question. (reducing chipher strength and enabling compression does not help. It seems some sort of initialization problem with x11 remote and local)
Mac user should install XQuartz instead of Xming.
And another important thing: if you install xquartz via homebrew, you should relogin your macos or reboot.
As the rackpas's answer saying.

Trying to access ipython notebook running on virtual machine

I would really appreciate some help here, basically I'm learning to use tensorflow, I've decided that the easiest way to go about this would be to install ubuntu on either VMware and/or Virtualbox and then access the ipython notebook (came with anaconda) through the browser on the host computer.
I have successfully installed both vmware and virtualbox, I downloaded a ubuntu image and also successfully installed anaconda on both, I get it to work without a problem on both VMs and even installed tensorflow.
Some research online on how to expose the ipython to the host machine suggested port forwarding or ssh tunneling, none of these have worked (very likely I'm doing it wrong). Can someone please help? think of me as a newbie.
Generally you must edit the jupyter configuration file to allow network access to the notebook server. See this link: http://jupyter-notebook.readthedocs.org/en/latest/public_server.html for details. (Even if it is not a "public" server, you still intend to access the notebook server living in the VM from the host machine via a network connection...)
Here is a quotation from the linked documentation that indicates by default, you can only access the notebook via the localhost.
By default, a notebook server runs locally at 127.0.0.1:8888 and is accessible only from localhost. You may access the notebook server from the browser using http://127.0.0.1:8888.

Categories