I wrote a Python 2.7 script based on the Python examples from google Adwords on github, installed the MySQL Connector from MySQL Page itself under Connectors.
And started with creating the script, but I am not able to find the bug which is causing that MySQL stops insert data or not even goes into the function.
No error messages, even removed all try and catch. Same.
If you like to check it for yourself: http://pastebin.com/WEQqBNHB
I used 5 Connections, because the functions call each other and it seems like if while is used you need one connection for it seperated.
MySQL Syntax is okay, as phpmyadmin is telling me.
Everything works exept Adgroups_AD/Adgroups_Performance
Any Ideas?
It seems like that i even need to commit select query's in python.
That fixed the issue. dang.
Related
Do you know if it's possible to create a role/user for the Postgresql database from within Python code?
I would prefer to use asyncpg library, since my program is based on asynchronous code, but if there are better libraries for this specific task, I don't mind using them.
I already have a pre-installed database on my server machine, so another possibility would be to just run the Shell command from withing the Python program to create a role. However, I am not sure if you can create a role in just one Shell line.
After some digging, the answer appeared to be very straightforward:
pool.execute("CREATE ROLE name ...")
I've never worked with sql/mysql but I've read a bunch of tutorials.
I want to be able to create databases with Python and then conveniently access it using mysql terminal tools.
In Mysql there are relational tables that can be handled by mysql terminal application. In order to access this from python I was able to use python connector.
There are also document store aka nosql databases. To work with this I used mysql-py shell (Chapter 20 of mysql 8.0 manual). However, I cannot access it from within the python, as I didn't find an appropriate module. I understand that there are a bunch of databases created for python, like mongo, but I want to use the original mysql tools.
Is there one? I work on MAC OS.
Thanks,
Mikhail
I found out the answer : X Dev API.
I'm working with a leveldb database (the leveldb wrapper, not plyvel); I ran a few test Put/Get/Delete operations on the database and everything was okay. (If it's relevant, I was accessing the database from 2 separate Python scripts.) Then I tried to make another database within a Python file that was already accessing the first database and I got this error:
leveldb.LevelDBError: IO error: lock ./states/LOCK: already held by process
So far I've tried deleting the database, uninstalling and reinstalling leveldb, deleting the LOCK file within the database, restarting my computer, and whatever this code snippet is. I'm kind of at my wits' end now; any advice you can offer would be greatly appreciated. Thanks.
per design, leveldb databases can only be held open by a single process at the time.
I currently simply have a local website on my Mac. I can view the webpage's HTMl and CSS and run the javascript functions in browser on my computer, but the next step I want to take is incorporating python scripts for accessing a MySQL database and returning results.
I am clearly new to this, and would love some guidance. Right now, on my computer, I have MySQL installed and I can run it in the terminal just fine. What else do I need as far as database and server equipment – if anything – to get some dynamic website running locally? My current, albeit incredibly limited, understanding is that I have a MySQL database stored on my machine that can be accessed through a Python script – also on my machine – and a link to this script in the HTML file. Is this even right, or do you recommend certain tutorials to fill in the gaps or teach me from the ground up?
I am sorry I am asking a lot; the few tutorials I have found have seemed to cover what I am hoping to do. Many thanks in advance.
Here you go. https://docs.djangoproject.com/en/1.4/intro/install/
Just follow the installation guide, and you'll be up and running in no time.
If you have MySQL installed on your machine along with Python, get a version of MySQLDb library for Python and have fun with it. Moreover, you can do almost any data operation with these combinations. If you want your website to go live (and do not wish to go through web frameworks) just look for a hosting plan that gives you a Python installed server access.
I've added new models and pushed to our staging server, run syncdb to create their tables, and it locks up. It gets as far as 'Create table photos_photousertag' and postgres output shows the notice for creation of 'photos_photousertag_id_seq', but otherwise i get nothing on either said. I can't ctrl+c the syncdb process and I have no indication of what route to take from here. Has anyone else ran into this?
We use postgres, and while we've not run into this particular issue, there are some steps you may find helpful in debugging:
a. What version of postgres and psycopg2 are you using? For that matter, what version of django?
b. Try running the syncdb command with the "--verbosity=2" option to show all output.
c. Find the SQL that django is generating by running the "manage.py sql " command. Run the CREATE TABLE statements for your new models in the postgres shell and see what develops.
d. Turn the error logging, statement logging, and server status logging on postgres way up to see if you can catch any particular messages.
In the past, we've usually found that either option b or option c points out the problem.
I just experienced this as well, and it turned out to just be a plain old lock on that particular table, unrelated to Django. Once that cleared the sync went through just fine.
Try querying the table that the sync is getting stuck on and make sure that's working correctly first.
Strange here too, but simply restarting the PostgreSQL service (or server) solved it. I'd tried manually pasting the table creation code in psql too, but that wasn't solving it either (well, no way it could if it was a lock thing) - so I just used the restart:
systemctl restart postgresql.service
that's on my Suse box.
Am not sure whether reloading the service/server might lift existing table locks too?