I use the neo4j python driver to write to my database.
I have my neo4j DB setup and was using ita few days ago without any issues.
Today i run my code and i get the following error:
Failed to write data to connection Address(host='localhost',
port=7687) (Address(host='xxx.x.x.x', port=7687));
("0; 'Underlying socket connection gone (_ssl.c:xxxx)'")
When i check via the browser and execute MATCH (n) RETURN n, it appears that all my querys still get executed bc i can find nodes in the database.
I shut my pc down, reinstalled neo4j and basically everything else.
(Its not only for CREATE statements but also for match statemenets)
Adding this at the end of the script worked for me.
db.driver.close()
Asusming you're using this driver, I suspect it might be related to this bug in neo4j-python-driver. It looks like their latest version fixes the bug, according to comments in the thread, but if not, maybe just downgrade back to whatever you were running before, and you should be fine.
It's usually a good idea to lock down your dependencies to avoid problems like this. Have a look at tools like pipenv or poetry if you're not familiar with them, they should save you a few headaches.
I'm uncertain where the issue lies, but the solve it to downgrade to python driver versions:
neo4j: 1.72
neobolt: 1.75
neotime: 1.75
Related
I am using jaydebeapi in python 3 to run queries.
I need to connect to Netezza and MySql both. my code runs both queries separately without any problem but when I run one after another it gives an error for the second one.
I close both connection and cursor for the first query (Netezza) but still get the following error:
jpype._jexception.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class com.mysql.jdbc.Driver not found
The issue isn't that you need to close one connection in order to use the other. The issue is that, when jaydebeapi is using jpype for communication, you only get one opportunity to provide all of the necessary JAR file paths you may use. This can be seen in the _jdbc_connect_jpype function, here.
The fix is to pass all JAR file paths you may use during execution of your program.
I'm assuming you aren't running on Jython and instead jaydebeapi
automatically installed jpype to facilitate Python to Java
communication. This is the most likely scenario for an "out of the
box" situation. If you are using Jython, let me know.
Yu need add Class Mysql Driver and JAR file path, example to DB2 with IMB jar:
conn = jaydebeapi.connect("com.ibm.as400.access.AS400JDBCDriver",
"url",
["user", "password"],
"C:\lib\jt400.jar",)
I have a Python script that uses sqlalchemy to create a MySQL schema.
Today I launched an Amazon RDS DB and successfully logged in, staring at a blinking cursor
mysql>
At this point, I realized I had no schema. The schema I want to use was written by someone else and it lives in a Python script.
Python is not installed; nor do I believe it should be. I simply have a MySQL database, yet no way to implement the tables.
How can I execute a Python script while on my AWS RDB, or is there some other way to go about this?
I suspect your issue is easily and intuitively solved with a slight conceptual shift on your part.
Ask yourself this:
Just now, which computer was I connected to when I saw the $ or C:\> or some other shell prompt? Which computer is the one where I was connected immediately before I saw the mysql> prompt?
Now, contrast that to the answer you would have given to the same question, if you were not using RDS? (I'll call this a "conventional" setup.)
In the latter question, the answer might be "the MySQL server," but in the former question, whichever machine it may be, the answer can't be "the MySQL server." You had to be somewhere else.
So, it seems like you are dealing with two different scenarios, but that isn't true. In actuality, in the conventional setup, the fact that you may be "on" the server is not really important, because programs and scripts that interact with MySQL may be running on the same machine, but they are still making a connection to the MySQL server process and operating at arm's length. People often run scripts (or their web server, etc.) on the server itself, assuming this has meaning, but it doesn't.
The place where you run the script is the computer you're using before connecting to MySQL... whether it's your laptop or an EC2 instance, or whatever. The script just needs to be connected to the MySQL server with the appropriate hostname, username, and password, when it runs from wherever it is running, whatever machine that happens to be.
EDIT 2:
Going to a MySQL shell prompt and launching a Python script from there is, AFAIK, not possible.
I need to make a python script that will do these steps in order, but I'm not sure how to go about setting this up.
SSH into a server
Copy a folder from point A to point B (cp /foo/bar/folder1 /foo/folder2)
mysql -u root -pfoobar (This database is accessible from localhost only)
create a database, do some other mysql stuff in the mysql console
Replaces instances of Foo with Bar in file foobar
Copy and edit a file
Restart a service
The fact that I have to ssh into a server, and THEN do all of this is really confusing me. I looked into the Fabric library, but that seems to do only do 1 command at a time and doesn't keep context from previous commands.
I looked into the Fabric library, but that seems to do only do 1 command at a time and doesn't keep context from previous commands.
Look into Fabric more. It is still probably what you want.
This page has a lot of good examples.
By "context" I'm assuming you want to be able to cd into another directory and run commands from there. That's what fabric.context_managers.cd is for -- search for it on that page.
Sounds like you are doing some sort of remote deployment/configuring. There's a whole world of tools out there to professionally set this up, look into Chef and Puppet.
Alternatively if you're just looking for a quick and easy way of scripting some remote commands, maybe pexpect can do what you need.
Pexpect is a pure Python module for spawning child applications; controlling them; and responding to expected patterns in their output.
I haven't used it myself but a quick glance at its manual suggests it can work with an SSH session fine: https://pexpect.readthedocs.org/en/latest/api/pxssh.html
I have never used Fabric.
My way to solve those kind of issues (before starting to use saltstack) it was using pyexpect, to run the ssh connection, and all the commands that were needed.
maybe the use of a series of sql scripts to work with the database (just to make it easier) would help.
Another way, since you need to access the remote server using ssh, it would be using paramiko to connect and execute commands remotely. It's a bit more complicated when you want to see what's happening on stdout (while with pexpect you will see exactly what's going on).
but it all depends from what you really need.
OK. So I've been treading on the thin edge of madness trying to get a Python virtualenv with Django set up. Tried a couple of different tutorials, first on Mac and then on Linux (Ubuntu), and always get as far as installing the Django package, and then I try and set up the database and everything just melts down. At first I was getting a lot of "mysql_config not found" and architecture compatibility errors (which was when I moved over to trying it on Linux)...now I think I've finally gotten it installed and not conflicting with anything and I don't know what to do next. I'm supposed to edit Django's settings file with the database info (name, UN, PW, and port), and I don't know where to look for this information.
So...my questions:
Is MySQL automatically running on Ubuntu if it is installed? If not, how do I turn it on?
Where do I edit databases? I'm a PHP person in general and this is early days with my forays into Python...I've generally done most of my database management through PHPMyAdmin...I know there's a command line for MySQL and I'd be able to use it but I don't know how to turn it on.
How do I find out what port MySQL is running on?
Again, this is an install in a virtualenv, if that makes any difference to the answers. I apologize if this is a totally noobish question but all the Django setup tutorials I've found seem to just assume I know this step.
Thanks much for any help!
1- mysql not installed on ubuntu by default, if you need to start mysql on the boot try:
chkconfig mysql on
2- mysql has a advanced commandline. just try in terminal:
mysql
use DB;
SELECT * FROM tbl1;
3- mysql runing on port 3306. and you can find port by this:
netstat -tnlp | grep mysql
finally you must be look at: Using PIP in a virtual environment, how do I install MySQL-python
I'm trying to convert a django / cPython app to run as a Tomcat WAR using Jython. We are using a mysql database (MySQLdb in cPython / mysql-connector-java-5.1.15-bin.jar in jython). I have changed the DATABASE_ENGINE between the two configurations. The app runs great with cPython (after I disabled SELinux limitations on http connections to a database). The front page, images, and static content work in the jython. However, when I request a page that hits the database, it seems to hang for a while, then returns with:
Communications link failure
The last packet sent successfully to
the server was 0 milliseconds ago. The
driver has not received any packets
from the server. [SQLCode: 0],
[SQLState: 08S01]
Has anyone seen this before? I don't see any recent discussions of this type or problem. I'm using django 1.2.5, jython 2.5.2. I've tried running the Java app under Fedora (jre-1.6.0-openjdk.x86_64) and Windows (Java(TM) SE Runtime Environment (build 1.6.0_23-b05)). Same behavior. I've also tried both mysql-connector-java-5.1.15-bin.jar (the latest version) and mysql-connector-java-5.1.10-bin.jar ("extensively tested" according to http://packages.python.org/django-jython/database-backends.html). None of the various configurations affect the behavior.
How can I solve it or where should I look next?
I found the mistake. In hindsight, it's obvious. I made a type-o in the IP address of the database server, but only in the configuration file on the jython branch. As a result, the Jython instance hung while the cPython instance didn't. Found the error when I merged the two into a single settings.py (using "if os.name=='java'" to make the necessary jython changes.
So . . . What's the correct protocol here? Should I delete the question or leave it up in case someone else makes the same type of mistake I did?