MySQL 1045 exception - python

I use Django 1.3.1 & Python 2.7.2 and I'm trying to deploy a project locally with nginx.
Something wrong with manage.py after executing the first command. For example: the first command is:
$ python manage.py runfcgi host=127.0.0.1 port=7782
and it works correctly. But when I try to execute any command after that, like syncdb or anything else (runserver, validate, runfcgi, etc...), I get strange exceptions:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 102, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 338, in get_server_version
self.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 250, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 322, in _cursor
self.connection = Database.connect(**kwargs)
File "/usr/lib/pymodules/python2.7/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: NO)")
I don't know what the reason is. In settings.py all MySQL access parameters (user, pass, dbname & host) are written correctly (syncdb succeed).
Note: if I copy the project directory for example to "project2" and rename it to original "project", the problem disappears for the first manage.py command I exectue, after that, I see the exceptions again.
I have another django projects deployed in the same way, using same django & python, but they work without any problem.
Anybody knows what the problem is?

Is your other Django project is set up on the same server/computer?
If it is, check your commas when you giving your db credentials and compare with the one which is running.

Related

django.db.utils.InterfaceError: connection already closed failures when updating to Django 3.0

I am updating a medium-sized project to Django 3.0 and I am encountering several errors in my tests after doing nothing more than bumping the Django version from 2.3.
The whole test suite has been running correctly for years and I couldn't find any relevant change in the changelog that may point to the cause of this issue. Apparently a single test fail is triggering every remaining test in the same TestCase class to fail with the following exception:
Traceback (most recent call last):
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/db/backends/base/base.py", line 238, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/utils/asyncio.py", line 24, in inner
return func(*args, **kwargs)
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", line 231, in create_cursor
cursor = self.connection.cursor()
psycopg2.InterfaceError: connection already closed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/federicobond/code/forks/core/apps/participants/tests/test_views.py", line 40, in setUp
self.client.force_login(self.user)
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/test/client.py", line 602, in force_login
self._login(user, backend)
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/test/client.py", line 611, in _login
if self.session:
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/test/client.py", line 461, in session
session.save()
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 81, in save
return self.create()
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 51, in create
self._session_key = self._get_new_session_key()
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 162, in _get_new_session_key
if not self.exists(session_key):
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 47, in exists
return self.model.objects.filter(session_key=session_key).exists()
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/db/models/query.py", line 777, in exists
return self.query.has_results(using=self.db)
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/db/models/sql/query.py", line 534, in has_results
return compiler.has_results()
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1107, in has_results
return bool(self.execute_sql(SINGLE))
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1135, in execute_sql
cursor = self.connection.cursor()
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/utils/asyncio.py", line 24, in inner
return func(*args, **kwargs)
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/db/backends/base/base.py", line 260, in cursor
return self._cursor()
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/db/backends/base/base.py", line 238, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/db/backends/base/base.py", line 238, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/utils/asyncio.py", line 24, in inner
return func(*args, **kwargs)
File "/Users/federicobond/code/forks/core/env/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", line 231, in create_cursor
cursor = self.connection.cursor()
django.db.utils.InterfaceError: connection already closed
I am out of ideas as to what could be going on here.
I ran into this as well. It appears to be a bug in pytest-django. Here's the relevant issue. There's an open PR to resolve it. If it's a big enough inconvenience you can use the branch in that PR or pin your dependencies to an earlier version.
We were hitting the same issue, and upgrading from Django 3.0.2 to Django-3.0.4 resolved it. There are several DB related fixes in those two versions, but I don't know which one solved our problem.
Just a forward note, it's near impossible to provide more information than already is in the stacktrace. However, you can investigate:
Check when the connection get closed and by which test (run them individually via script for example).
For tests that fail, check the code for deprecated parts of Django (searching for things that were removed/deprecated between 2.3 and 3.0).
Run a linter to see if someone changed a private variable inside of Django framework as workaround.
Check the transactions of postgres.
Then once you have which part of the code has the error narrow it down by creating smaller failing tests.
I had the same issue using pytest.
Downgrading from 5.4.1 to 5.3.5 fixed it.
All these issues occur because of the incompatibility of the other packages with django 3.0
when i ran into this error i updated my requirement.txt file manually and then intalled all the requirements using pip in the same env.

How do I install GNUHealth?

I am following the installation steps mentioned below but have encountered a python problem.
https://en.wikibooks.org/wiki/GNU_Health/Installation#Installing_GNU_Health_on_GNU/Linux_and_FreeBSD
At the step where the initialisation of the database instance is to be performed, I have encountered the following error after executing the following command.
python3 ./trytond-admin --all --database=health
Error encountered:
Traceback (most recent call last):
File "./trytond-admin", line 21, in <module>
admin.run(options)
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-4.6.18/trytond/admin.py", line 24, in run
with Transaction().start(db_name, 0, _nocache=True):
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-4.6.18/trytond/transaction.py", line 88, in start
database = Database(database_name).connect()
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-4.6.18/trytond/backend/postgresql/database.py", line 97, in __new__
**cls._connection_params(name))
File "/home/gnuhealth/.local/lib/python3.6/site-packages/psycopg2/pool.py", line 161, in __init__
self, minconn, maxconn, *args, **kwargs)
File "/home/gnuhealth/.local/lib/python3.6/site-packages/psycopg2/pool.py", line 58, in __init__
self._connect()
File "/home/gnuhealth/.local/lib/python3.6/site-packages/psycopg2/pool.py", line 62, in _connect
conn = psycopg2.connect(*self._args, **self._kwargs)
File "/home/gnuhealth/.local/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: fe_sendauth: no password supplied
Can anyone help me out with this error or tell me what I am missing?
Based on the error, I suspect that there's a difficulty in connecting to the DB as there is no password specified.
It seems that you did not configured the URI with the credentials to connect to the database. You can find the description of the configuration file at http://docs.tryton.org/projects/server/en/latest/topics/configuration.html#uri
Once you have a configuration file, you must run the command like this:
python3 ./trytond-admin --all --database=health -c /path/to/trytond.conf

Password input may be echoed when run Python Fabric command in crontab

I encountered issue when trying to run my program through crontab on Mac OS. My program works fine when run it independently. Normally, I never set env.password for remote system password. For instead, I set env.key_filename. It works fine if i don't have to run sudo command. So ideally, it shouldn't prompt any password typing.
By referring to https://github.com/fabric/fabric/issues/1230, i also tried to set environment variables to pass the password. Yet, i still get the same error. What did i miss? Anyone can help pls?
Thx
Error msg:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getpass.py:83: GetPassWarning: Can not control echo on the terminal.
passwd = fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
[xxx.xxx.xxx.xxx] Login password for 'xxx': [xxx.xxx.xxx.xxx] Executing task 'System.Monitor.free_mem'
[+] Start checking system total/free memory in MB:
[xxx.xxx.xxx.xxx] run: free -m
Traceback (most recent call last):
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/main.py", line 757, in main
*args, **kwargs
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/tasks.py", line 386, in execute
multiprocessing
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/tasks.py", line 276, in _execute
return task.run(*args, **kwargs)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/tasks.py", line 173, in run
return self.wrapped(*args, **kwargs)
File "/Users/thomas.pan/Python-ninja/playwith/DevOps/System/Monitor.py", line 69, in free_mem
run("free -m")
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 687, in host_prompting_wrapper
return func(*args, **kwargs)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/operations.py", line 1090, in run
shell_escape=shell_escape, capture_buffer_size=capture_buffer_size,
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/operations.py", line 930, in _run_command
channel=default_channel(), command=wrapped_command, pty=pty,
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/state.py", line 424, in default_channel
chan = _open_session()
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/state.py", line 416, in _open_session
return connections[env.host_string].get_transport().open_session()
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 159, in __getitem__
self.connect(key)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 151, in connect
user, host, port, cache=self, seek_gateway=seek_gateway)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 569, in connect
password = prompt_for_password(text)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 652, in prompt_for_password
new_password = _password_prompt(password_prompt, stream)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 624, in _password_prompt
return getpass.getpass(prompt.encode('ascii', 'ignore'), stream)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getpass.py", line 83, in unix_getpass
passwd = fallback_getpass(prompt, stream)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getpass.py", line 118, in fallback_getpass
return _raw_input(prompt, stream)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getpass.py", line 135, in _raw_input
raise EOFError
EOFError
Issue closed by switch to launchd with LaunchControl tool. It's not Fabric issue.
In case it helps anyone - if you're running a command that is logging into an instance, this GetPassWarning/OEFError issue can happen with a cron job, since the shell session does not know how to log into that instance.
To fix this, you may need to give ssh context to crond. ssh-cron can do this, for example, since it looks like there is difficulty getting that all set up in crontab.

issues with OpenERP installation

I am installing openerp at my local server, I have installed it and its dependences but after finishing its installation when i run server 'openerp-server' and acces it using 0.0.0.0:8069/. I got the following error
OpenERP Server Error
Client Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/http.py", line 195, in dispatch
response["result"] = method(self, **self.params)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/controllers/main.py", line 709, in get_list
return db_list(req)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/controllers/main.py", line 88, in db_list
dbs = proxy.list()
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/session.py", line 31, in proxy_method
result = self.session.send(self.service_name, method, *args)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/session.py", line 104, in send
raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)
Server Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/session.py", line 90, in send
return openerp.netsvc.dispatch_rpc(service_name, method, args)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/netsvc.py", line 295, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/service/web_services.py", line 122, in dispatch
return fn(*params)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/service/web_services.py", line 351, in exp_list
cr = db.cursor()
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/sql_db.py", line 477, in cursor
return Cursor(self._pool, self.dbname, serialized=serialized)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/sql_db.py", line 183, in __init__
self._cnx = pool.borrow(dsn(dbname))
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/sql_db.py", line 378, in _locked
return fun(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/sql_db.py", line 433, in borrow
result = psycopg2.connect(dsn=dsn, connection_factory=PsycoConnection)
File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect
connection_factory=connection_factory, async=async)
OperationalError: FATAL: role "ghrix" does not exist
I haven't recognize this error.
One more thing , I haven't edit OpenERP server configuration file . And if I have to edit this file then what are those changes.
Thanks.
This error indicates that OpenERP is trying to connect to the PostgreSQL database server using the "ghrix" user, which does not exist. This is probably the user under which you are starting the server.
If you have created a special database user for OpenERP you need to specify it on the command-line using --db_user=DB_USER (and in that case you probably also need --db_host=localhost and --db-password=YOUR_PASSWORD).
If you haven't created any database user yet, the easiest solution is probably to create one named ghrix, e.g.:
$ sudo su - postgres
$ createuser -s ghrix # -s to make a super-user that can create DBs
Note: Use ./openerp-server --help to see all possible startup parameters for the OpenERP server. You can also put the command-line options in a config file: just execute
$ ./openerp-server -s
and then edit the sample config file that is created in $HOME/.openerp_serverrc
Even though the question has been answered, the following is a concise tutorial on installing a production grade OpenERP Server, that also explains how to set up the database, manage access rights and configure your OpenERP installation:
http://www.theopensourcerer.com/2012/02/how-to-install-openerp-6-1-on-ubuntu-10-04-lts/
you should check two case
First case:
$ sudo su - postgres $ createuser -s ghrix
second case
fill the db user and db password in
/odoo/debian/odoo.conf
run odoo with this parameter
./odoo-bin -c /opt/odoo/debian/odoo.conf
If not resolved comment below i try to resolve it

Access denied to ClearDB database using Python/Django on Heroku

I'm trying to build a webapp on Heroku using Python/Django, and I just followed the tutorial to set up a Django project and push it to Heroku. However, I can never even get to the normal Django "It worked!" screen. Of course, that is because when I check heroku ps, there are never any processes running. There is no Procfile but according to the tutorial, that shouldn't matter for a Django app.
When I run heroku run python manage.py runserver, the following error occurs:
Unhandled exception in thread started by <bound method Command.inner_run of <dja
ngo.contrib.staticfiles.management.commands.runserver.Command object at 0x1ff819
0>>
Traceback (most recent call last):
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/com
mands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/bas
e.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/val
idation.py", line 103, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/v
alidation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/b
ase.py", line 411, in get_server_version
self.cursor()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/__init_
_.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/b
ase.py", line 387, in _cursor
self.connection = Database.connect(**kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/MySQLdb/__init__.py", line
81, in Connect
return Connection(*args, **kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/MySQLdb/connections.py", l
ine 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1044, "Access denied for user '<user>
'#'%' to database 'heroku_<####################>?reconnect=true'")
I did already set my DATABASE_URL to the value of CLEARDB_DATABASE_URL. Also, in the Django settings.py, I added as instructed:
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
Any help would be greatly appreciated.
That particular error was fixed after calling ClearDB. Turns out that the ?reconnect=true is only for Rails apps, and should be removed from the DATABASE_URL for Django apps.

Categories

Resources