I am getting the following error:
db assertion failure, assertion: 'unauthorized db:db1 lock type:-1 client:', assertionCode: 10057
I am able to access the MongoDB database by running python on the shell of my server. But when I try to access my site i get this unauthorised errors.
Any fix for this error?
This means that your database is using authentication. In such a setup, you must authenticate a valid user before you can perform any operations (queries, commands, updates, etc). You can do so with the db.auth(username, password) helper in the mongo shell (described in the MongoDB docs), and with Python, you can use the authenticate(username, password) method of the Database object (described in the PyMongo docs)
Related
I'm working on a project with python3 and BigQuery and i encountered a strange behavior in google-cloud-bigquery library.
When i exec simple query like:
select * from my.project where field1="foo" and field2="bar"
The program running well but when I try to use a more "complex" query like:
with a as (...),b as(...)
select * from a as a_el
select * from b as b_el
join b_el on a_el.field1 = b_el.field1 ...
The program crash with:
google.api_core.exceptions.PermissionDenied: 403 request failed: the user does not have 'bigquery.readsession.create' permission
So, I know this is a permission problem but my question is: what's the difference under the hood? Why extra permission are needed? The tables are in the same project, so where is the problem?
I use query() method for execute queries
The google-cloud-bigquery python library leverages the BigQuery Storage read api to download query results faster. The permissions are part of the roles/bigquery.user predefined role. Likely you've got a custom role on the project that excludes the readsession permissions, which are permissions specific to the BigQuery storage API. This sounds like a case where the results from the first query are small enough that the storage API session doesn't get created.
More information about permissions can be found on the access control page.
I want to get the list of DBs on a remote server with a python script.
I know I can connect to a certain db with
import ibm_db
ibm_db.connect("DATABASE=name;HOSTNAME=host;PORT=60000;PROTOCOL=TCPIP;UID=username;
PWD=password;", "", "")
however I want to only connect to an instance and then do "db2 list db directory" to get the DB names.
Meaning change to the instance user and set off that command or preferably use a python module that can do just that. I only need the names no real connection to a database.
The result should be an array with all database names in that instance.
Any ideas or help?
Thank you
Unfortunately, there is no such function in python-ibmdb API and actually not even in full Db2 API. The only "workaround" I could think of would be UDF deployed on the remote database that uses db2DbDirOpenScan to access the catalog and return the info via the connection that is already established.
I want to setup a local db2 database to allow local users to connect without using password (specifically via python).
I can connect to the database from cli w/o password as db2 connect to <DATABASE>.
However, when trying to connect from within python using official ibm_db api as
ibm_db.connect("database", "", "")
throws the following error:
SQL 300082N Security processing failed with reason "17" ("UNSUPPORTED FUNCTION"). SQLSTATE=08001 SQLCODE=-30082
Based on the documentation for authentication options, I have set the following options:
AUTHENTICATION=CLIENT
TRUST_CLNTAUTH=CLIENT
TRUST_ALLCLNTS=YES
however, I am still getting the same error.
P.S. #1: I am not concerned about user authentication as they have already been authenticated before been allowed to log in to the server.
P.S. #2: A similar question has already been asked at DB2 connection without specifying username and password. However, I need to connect via python and even with the setting 1 and 3 prescribed in the accepted answer, the connection fails.
P.S. #3: Possibly relevant link - http://www-01.ibm.com/support/docview.wss?uid=swg21237107
I am attempting to run a script written in Python 2.7.5 (not using Django). When it tries to connect to a remote mysql server with the MySQLdb.connect() method it throws the following error:
_mysql_exceptions.OperationalError: (2049, "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)")
I have done reading about this issue:
Django/MySQL-python - Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)
mysql error 2049 connection using old (pre-4-1-1) authentication from mac
Is there a way to set a parameter in the MySQLdb.connect() method to set secure_auth to false? Without having to change any passwords or running the command from the cmd line. I have looked at the official docs and there does not appear to be anything in there.
I have tried adding secure_auth=False to the parameters but throws an error (shown in the code below).
Python:
def get_cursor():
global _cursor
if _cursor is None:
try:
db = MySQLdb.connect(user=_usr, passwd=_pw, host='external.website.com', port=3306, db=_usr, charset="utf8")
# tried this but it doesnt work (as expect but tried anyway) which throws this error
# TypeError: 'secure_auth' is an invalid keyword argument for this function
# db = MySQLdb.connect(user=_usr, passwd=_pw, host='external.website.com', port=3306, db=_usr, charset="utf8", secure_auth=false)
_cursor = db.cursor()
except MySQLdb.OperationalError:
print "error connecting"
raise
return _cursor
I spent an inordinate amount of time working through the MySQLdb source code and determined that this simply cannot be done without patching the MySQLdb's C wrapping code. Theoretically, you should be able to pass the SECURE_CONNECTION flag to specify that do not want to use the insecure old passwords:
MySQLdb.connect(..., client_flags=MySQLdb.constant.CLIENT.SECURE_CONNECTION)
But the MySQLdb code never actually checks that flag, and never configures the secure_connection option when calling the MySQL connection code, so it always defaults to requiring new-style passwords.
Possible fixes include:
Patch the MySQLdb code
Use an old version of the MySQL client libraries
Update the passwords on the MySQL server
Create a single new user with a new-style password
Sorry I don't have a better answer. I just ran into this problem myself!
I know Moses answer as been validated but I wanted to offer my work around based on what he suggested.
I had previously installed mysql_python for my python and had the brew version of mysql installed.
I deteleted all of that.
I look for a way to install MySQLdb by looking for it last stable version with the source.
I compiled them (followed the isntructions here), installed them and then I looked for a stable version of MySQL client (MySQL website is the best place for that) and install the 5.5 version which was perfectly fitting my requirements.
I made mysql to launch itself automatically and then restarted my computer (but you can just restart apache) and check that all path were correct and the right includes are in the right places (you can check that against the link above).
And now it all works fine!
Hope it helps.
SSL is a separate paramter that you can set in the connection paramter...Here is a note from the source code...Try checking mysql_ssl_set() documentation.
ssl
dictionary or mapping, contains SSL connection parameters;
see the MySQL documentation for more details
(mysql_ssl_set()). If this is set, and the client does not
support SSL, NotSupportedError will be raised.
This document talks about all the secure parameters - http://dev.mysql.com/doc/refman/5.0/en/mysql-ssl-set.html...
I don't see anything to disable secure auth in glance..
I am attempting to connect and authenticate to a remote database host (dotcloud, mongolabs, etc) using MongoKit within Flask. Connecting to the server seems to work fine. However I am unable to authenticate to the database. Presumably this should work:
from mongokit import Connection
connection = Connection(my_remote_host, my_remote_port)
connection.my_database.authenticate(my_admin_user, my_admin_password)
the call to authenticate() returns True, yet subsequent calls to fetch data throw:
OperationFailure: database error: unauthorized db
Anyone know what might be happening here?
This is likely due to the current behavior of authenticate() in pymongo. Pymongo doesn't cache authentication credentials between threads, so each thread must authenticate individually. See the note in the pymongo documentation about using authenticate() in a multi-threaded environment.