Pycharm 4.5.3 remote console 'cannot connect to remote process' - python

Starting today for no discernible reason, Pycharm's remote console function will not connect with my remote server.
All other functions are working as normal, SSH session, deployment config, skeletons update, file sync etc.
I am running Pycharm 4.5.3 on Windows7x64 against a remote server running Centos6.5x64 on AWS, note that this setup has been working fine for months until today.
The following output appears in the console window when remote console is launched, it takes a minute or so to timeout:
sftp://user#FQDN:22/home/user/Envs/lab1/bin/python2.7 -u /home/user/.pycharm_helpers/pydev/pydevconsole.py 0 0
Couldn't connect to console process.
Process finished with exit code -1
Unhelpful Log output(C:\Users\user\.PyCharm40\system\log\idea.txt):
2015-07-09 17:15:07,910 [ 236325] INFO - esdk.transport.JschExecProcess - Executing ssh command: env "PYTHONIOENCODING"="UTF-8" "JETBRAINS_REMOTE_RUN"="1" "IPYTHONENABLE"="True" "PYTHONUNBUFFERED"="1" /home/user/Envs/lab1/bin/python2.7 -u /home/user/.pycharm_helpers/pydev/pydevconsole.py 0 0 for user#FQDN:22
The following troubleshooting steps have yielded nothing: Workstation / Server, reboot, Fresh Virtualenv, Different version of Python, reinstall of iPython, uninstall of iPython, reset of console / deployment configuration, connecting from a different workstation running same version of Pycharm, upgrade Pycharm from 4.5.2 to 4.5.3.
Suggestions for further troubleshooting steps gladly welcome while I wait for Jetbrains support to get around to my ticket!

The problem was within the security configuration on AWS.
My AWS instance has a friendly FQDN to go with the unfriendly AWS internal name, which appears to cause some havoc with the way their NAT works if you don't have a rule allowing traffic from the IP bound to the FQDN back into the server.
I created the issue yesterday when my office router reset to a new IP - I must've overwritten the recursive rule with the rule allowing my new office IP into the instance.
So, add a rule allowing the server public IP for all traffic and Pycharm connects again when pointed at the FQDN.

Related

Access denied with remote mysql connector python3 connection

Connection problem solved! Leaving for others who may have issue.
Still having problems with bind-address issues
I will state the problem, the loayout context of my system and things I have tried.
Problem: When trying to use mysql connector in a python file i keep getting access denied. I am using Pycharm as my IDE and I have the Mysql connector installed though that.
So I am running Ubuntu Server on a Orale VM on a Windows 10 desktop, it's a bridged connection and I can SSH in from my laptop (LInux Mint)to the server just fine. I am running the program trying to access the DB on the Linux Mint laptop. Local network only using 192.168.0.xxx protocols. All VPN's disabled at this point for now.
So just to state i reinstalled the server last night and I set up fresh users and DB for the user and even granted ALL PRIVILEGES to the user and connections from my connectiong machines.
i set bind address in my mysqld.cnf file to 0.0.0.0 for now.
(when i had it set to my laptop ip it wouldn't bind and would restart until I switched it back)
UFW is set to allow mysql(3306)
Ask all the questions and I will get you answers asap. Please provide commands for me to run if needed and specify if the should be ran on the server or my laptop. Thanks for reading!

Can't connect to django application running on AWS Ubuntu EC2

I am runnig my Django application on AWS EC2 t2.micro with Ubuntu. I've successfuly installed all modules, created a PostgreSQL database, and made all migrations. Now when I'm running python manage.py runserver 172.31.27.208:8000 I can't connect to it in browser, getting ERR_CONNECTION_TIMED_OUT error.
python manage.py runserver 172.31.27.208:8000 returns:
System check identified no issues (0 silenced).
January 30, 2020 - 11:10:59
Django version 3.0.2, using settings 'project_test.settings'
Starting development server at http://172.31.27.208:8000/
Quit the server with CONTROL-C.
So I assume the server running properly.
I am using private ip form ec2 console which, I've checked, is matching to the ip adress returning by running command ifconfig.
TCP port is opened in AWS security_group inbound rules on port 8000.
I've also checked netstat -lan after running django server, it shows:
tcp 0 0 172.31.27.208:8000 0.0.0.0:* LISTEN
I have been looking for same issues and everything listed in them seems to be correct in my case. Since that I have no idea what is going wrong. Can provide more information if you need something. Will appriciate any help. Thank you.

How do I run pycharm within my docker container?

I'm very new to docker. I want to build my python application within a docker container. As I build the application I want to be testing / running it in Pycharm and in the container I build.
How do I connect Pycharm pro to a specific container or image (either python or Anaconda)?
When I create a project, click pure python and then add remote, then clicking docker I get the following result
I'm running on Mac OS X El Capitan (10.11.6) with Docker version 1.12.1 and Pycharm Pro 2016.2.3
Docker-for-mac only supports connections over the /var/run/docker.sock socket that is listening on your OSX host.
If you try to add this to pycharm, you'll get the following message:
"Cannot connect: java.lang.ExceptionInInitializerError, caused by: java.lang.IllegalStateException: Only supported on Linux"
So PyCharm really only wants to connect to a docker daemon over a TCP socket, and has support for the recommended TLS protection of that socket. The Certificates folder defaults to the certificate folder for the default docker-machine machine, "default".
It is possible to implement a workaround to expose Docker for Mac via a TCP server if you have socat installed on your OSX machine.
On my system, I have it installed via homebrew:
brew install socat
Now that's installed, I can run socat with the following parameters:
socat TCP-LISTEN:2376,reuseaddr,fork,bind=127.0.0.1 UNIX-CLIENT:/var/run/docker.sock
WARNING: this will make it possible for any process running as any user on your whole mac to access your docker-for-mac. The unix socket is protected by user permissions, while 127.0.0.1 is not.
This socat command tells it to listen on 127.0.0.1:2376 and pass connections on to /var/run/docker.sock. The reuseaddr and fork options allow this one command to service multiple connections instead of just the very first one.
I can test that socat is working by running the following command:
docker -H tcp://127.0.0.1:2376 ps
If you get a successful docker ps response back, then you know that the socat process is doing its job.
Now, in the PyCharm window, I can put the same tcp://127.0.0.1:2376 in place. I should get a "Connection successful" message back:
This workaround will require that socat command to be running any time you want to use docker from PyCharm.
If you wanted to do the same thing, but with TLS, you could set up certificates and make them available for both pycharm and socat, and use socat's OPENSSL-LISTEN instead of the TCP-LISTEN feature. I won't go into the details on that for this answer though.

pycharm can't complete remote interpreter setup for Docker

I'm new to Docker. I'm using Docker & docker-compose, going through a flask tutorial. The base docker image is python 2.7 slim.
It's running on Linux. docker 1.11.2
The application is working fine.
I want to get pycharm pro connecting to the remote interpreter, something I have never done before.
I followed the instructions for docker-compose. Initially it was failing because it could not connect to port 2376. I added this port to docker-compose.yml and the error went away.
However, trying to save the configuration now stalls/hangs with a dialog 'Getting Remote Interpreter Version'. This never completes. Also, I can't quit pycharm. This happens in Pycharm 2016.2 and 2016.3 EAP (2nd).
The help say "SFTP support is required for copying helpers to the server".
Does this mean I need to do something?
I'm not using docker-machine
The problem was that TCP access to the docker API is not established by default under ubuntu 16.04.
There are suggestions to enable TCP/IP access.
However, JetBrains gave me the simplest solution:
If you are using Linux it is most likely that Docker installed with
its default setup and Docker is expecting to be used through UNIX
domain file socket /var/run/docker.sock. And you should specify
unix:///var/run/docker.sock in the API URL field. Please comment
whether it helps!
This suggestion worked with my Ubuntu 16.04 -derived distribution.
This goes into the Docker entry in PyCharm preferences under Build, Execution, Deployment.
You can also edit this while setting up a remote interpreter, but only by making a new Docker entry.
TCP/IP Method
This method works if you want TCP/IP access, but this is a security risk. The socket approach is better, which is probably why it is the default.
https://coreos.com/os/docs/latest/customizing-docker.html
Customizing docker
The Docker systemd unit can be customized by overriding the unit that
ships with the default CoreOS settings. Common use-cases for doing
this are covered below.
Enable the remote API on a new socket
Create a file called /etc/systemd/system/docker-tcp.socket to make
Docker available on a TCP socket on port 2375.
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=2375
BindIPv6Only=both
Service=docker.service
[Install]
WantedBy=sockets.target
Then enable this new socket:
systemctl enable docker-tcp.socket
systemctl stop docker
systemctl start docker-tcp.socket
systemctl start docker
Test that it’s working:
docker -H tcp://127.0.0.1:2375 ps
Once I thought to search for ubuntu 16.04 I came across simpler solutions, but I did not test them.
For instance:
https://www.ivankrizsan.se/2016/05/18/enabling-docker-remote-api-on-ubuntu-16-04/
Edit the file /lib/systemd/system/docker.service
Modify the line that starts with ExecStart to look like this:
ExecStart=/usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:2375
Where my addition is the “-H tcp://0.0.0.0:2375” part. Save the
modified file. Restart the Docker service:
sudo service docker restart
Test that the Docker API is indeed accessible:
curl http://localhost:2375/version
I - docker-compose up
I think PyCharm will run docker-compose up, have you try to run this command first in your terminal (from where your docker-compose.yml is) ?
Maybe if some errors occur, you will get more info in your terminal.
II - pycharm docker configuration
Otherwise it could be due to your docker machine configuration in PyCharm.
What I do to configure my machine and to be sure this one is correctly configured:
1 - run docker-machine ls in your shell
2 - copy paste the url without tcp://
3 - go to pycharm preferences -> Build, Execution, Deployement -> Docker -> + to create a new server, fill the server name field
4 - paste previously copied url keeping https://
5 - fill the path of your machine certificates folder
6 - tick Import credentials from Docker Machine
7 - click Detect -> your machine should appear in the selection list
8 - save this server
9 - select this server when configuring your remote interpreter, from PyCharm Preferences -> Project -> Project Interpreter -> wheel -> add remote -> Docker or Docker Compose
10 - you should be able to select a service name
11 - save your new interpreter
11 - try run your test twice, sometimes it could take time to initialize

How to remote debug in PyCharm

The issue I'm facing right now:
I deploy Python code on a remote host via SSH
the scripts are passed some arguments and must be ran by a specific user
the PyCharm run/debug configuration that I create connects through SSH via a different user (can't connect with the user that actually runs the scripts)
I want to remote debug this code via PyCharm...I managed to do all configuration, I just get permission errors.
Are there any ways on how I can run/debug the scripts as a specific user (like sudo su - user)?
I've read about specifying some Python Interpeter options in PyCharm's remote/debug configuration, but didn't manage to get a working solution.
If you want an easy and more flexible way to get into the PyCharm debugger, rather than necessarily having a one-click "play" button in PyCharm, you can use the debug server functionality. I've used this in situations where running some Python code isn't as simple as running python ....
See the Remote debug with a Python Debug Server docs for more details, but here's a rough summary of how it works:
Upload & install remote debugging helper egg on your server (On OSX, these are found under /Applications/PyCharm.app/Contents/debug-eggs)
Setup remote debug server run configuration: click on the drop-down run configuration menu, select Edit configurations..., hit the + button, choose Python remote debug.
The details entered here (somewhat confusingly) tell the remote server running the Python script how to connect to your laptop's PyCharm instance.
set Local host name to your laptop's IP address
set port to any free port that you can use on your laptop (e.g. 8888)
Now follow the remaining instructions in that dialog box: copy-paste the import and pydevd.settrace(...) statements into your code, specifically where you want your code to "hit a breakpoint". This is basically the PyCharm equivalent of import pdb; pdb.set_trace(). Make sure the changed code is sync'ed to your server.
Hit the bug button (next to play; this starts the PyCharm debug server), and run your Python script just like you'd normally do, under whatever user, environment etc. When the breakpoint is hit, PyCharm should drop into debug mode.
I have this (finally) working with ssh RemoteForward open, like so:
ssh -R 5678:localhost:5678 user#<remotehost>
Then start the script in this ssh session. The python script host must connect to localhost:5678 and of course your local pycharm debugger must listen to 5678
(or whatever port you choose)

Categories