ArangoDB Connection error from python - arangodb

Trying to connect to ArangoDB using python
Code:
from pyArango.connection import *
conn = Connection(username="root", password="XXXXX")
Got below error
Trace:
Traceback (most recent call last):
File "E:/Python/Nlp/imageTotext.py", line 177, in <module>
conn = Connection(username="root", password="XXXXX") File "C:\Users\am843946\AppData\Roaming\Python\Python27\site-packages\pyArango\connection.py",
line 105, in __init__
self.reload() File "C:\Users\am843946\AppData\Roaming\Python\Python27\site-packages\pyArango\connection.py",
line 124, in reload
data = r.json() File "C:\Users\am843946\AppData\Roaming\Python\Python27\site-packages\pyArango\connection.py",
line 19, in __call__
raise e ValueError: No JSON object could be decoded

did you try to specify a connection URL like that?
conn = Connection(arangoURL="http://localhost:8529", username="root", password="")
That way it should work.

Related

Qiskit code: function BaseAnalysis.run.<locals>.run_analysis is failed

when I run my qiskit code as below on azure,
circ_1a = QuantumCircuit(1)
circ_1a.h(0)
exp_1a = StateTomography(circ_1a)
data = ExperimentData(experiment = exp_1a)
data.add_data(jobs)
data = exp_1a.analysis.run(data)
it always shows me an error like this:
even this code works for other people, but it didn't work for my workspace
Analysis callback <function BaseAnalysis.run.<locals>.run_analysis at 0x7f8246ab6dd0> failed:
Traceback (most recent call last):
File "/home/jovyan/.local/lib/python3.7/site-packages/qiskit_experiments/database_service/db_experiment_data.py", line 299, in _wrapped_callback
callback(self, **kwargs)
File "/home/jovyan/.local/lib/python3.7/site-packages/qiskit_experiments/framework/base_analysis.py", line 168, in run_analysis
results, figures = analysis._run_analysis(expdata)
File "/home/jovyan/.local/lib/python3.7/site-packages/qiskit_experiments/library/tomography/tomography_analysis.py", line 107, in _run_analysis
experiment_data.data()
File "/home/jovyan/.local/lib/python3.7/site-packages/qiskit_experiments/library/tomography/tomography_analysis.py", line 302, in _fitter_data
metadata = datum["metadata"]
KeyError: 'metadata'
Does anyone know what's this problem?

Airflow InitDB issue

I am getting below error when i run airflow initdb after changing SQLALchemy details to connect to MySQL in airflow.cfg file.
Traceback (most recent call last):
File "/home/ec2-user/.local/bin/airflow", line 25, in <module>
from airflow.configuration import conf
File "/home/ec2-user/.local/lib/python3.7/site-packages/airflow/__init__.py", line 47, in <module>
settings.initialize()
File "/home/ec2-user/.local/lib/python3.7/site-packages/airflow/settings.py", line 405, in initialize
configure_orm()
File "/home/ec2-user/.local/lib/python3.7/site-packages/airflow/settings.py", line 294, in configure_orm
engine = create_engine(SQL_ALCHEMY_CONN, connect_args=connect_args, **engine_args)
File "/home/ec2-user/.local/lib/python3.7/site-packages/sqlalchemy/engine/__init__.py", line 500, in create_engine
return strategy.create(*args, **kwargs)
File "/home/ec2-user/.local/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/home/ec2-user/.local/lib/python3.7/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 118, in dbapi
return __import__("MySQLdb")
File "/home/ec2-user/.local/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
import _mysql
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
Please help on this issue

What should I infer from the error: AttributeError: 'str' object has no attribute 'setdefault'

I have a python repository, which tries to connect with a database available on web and collect the relevant data. Now when I run the repo from local machine, I get the desired database and hence the output.
However, when I run the same code from the Windows Server and tries to connect the same website(proxy), I am getting the above error.
I have installed/uninstalled the respective ODBC driver but no luck
Can anyone suggest me any method to get out of this?
(ssf) C:\Users\admin-prakuma3\data-model_1>python main.py
Traceback (most recent call last):
File "main.py", line 612, in <module>
salesforce_daily_extractors()
File "main.py", line 44, in salesforce_daily_extractors
'StartDate': 'StartDate'
File "C:\Users\admin-prakuma3\data-model_1\SalesforceExtractor.py", line 23, in __run__
fields = sg.getConnection(sg).__getattr__(sfdc_object).describe()['fields']
File "C:\Users\admin-prakuma3\data-model_1\SalesforceGateway.py", line 19, in getConnection
security_token='************', proxies="*******:8080")
File "C:\Users\admin-prakuma3\.conda\envs\ssf\lib\site-packages\simple_salesforce\api.py", line 146, in __init__
domain=self.domain)
File "C:\Users\admin-prakuma3\.conda\envs\ssf\lib\site-packages\simple_salesforce\login.py", line 168, in SalesforceLogin
proxies=proxies)
File "C:\Users\admin-prakuma3\.conda\envs\ssf\lib\site-packages\requests\sessions.py", line 535, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "C:\Users\admin-prakuma3\.conda\envs\ssf\lib\site-packages\requests\sessions.py", line 479, in request
prep.url, proxies, stream, verify, cert
File "C:\Users\admin-prakuma3\.conda\envs\ssf\lib\site-packages\requests\sessions.py", line 656, in merge_environment_settings
proxies.setdefault(k, v)
AttributeError: 'str' object has no attribute 'setdefault'

Cannot run bind() with ldap3 in python3

Below is my code to try and query my ldap server. However, for some reason, I cannot seem to make the bind command work to progress in my code. I continue to get the following message and am not sure what it means or how to fix it. I apologize about the error message formatting. I tried my best to make it as readable as possible.
Any help would be greatly appreciated!
>>> from ldap3 import Server, Connection, SUBTREE
>>> server = Server('<server_name>')
>>> conn = Connection(server, user='<username>', password='<password>')
>>> conn.open()
>>> conn.bind()
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.5/site-packages/ldap3/core/connection.py", line 427, in bind
response = self.post_send_single_response(self.send('bindRequest', request, controls))
File "/usr/lib/python3.5/site-packages/ldap3/strategy/sync.py", line 122, in post_send_single_response
responses, result = self.get_response(message_id)
File "/usr/lib/python3.5/site-packages/ldap3/strategy/base.py", line 298, in get_response
responses = self._get_response(message_id)
File "/usr/lib/python3.5/site-packages/ldap3/strategy/sync.py", line 168, in _get_response
dict_response = self.decode_response(ldap_resp)
File "/usr/lib/python3.5/site-packages/ldap3/strategy/base.py", line 403, in decode_response
result = bind_response_to_dict(component)
File "/usr/lib/python3.5/site-packages/ldap3/operation/bind.py", line 119, in bind_response_to_dict
'saslCreds': bytes(response['serverSaslCreds']) if response['serverSaslCreds'] is not None else None}
File "/usr/lib/python3.5/site-packages/pyasn1/type/univ.py", line 984, in bytes
return bytes(self._value)
File "/usr/lib/python3.5/site-packages/pyasn1/type/base.py", line 164, in plug
raise error.PyAsn1Error('Uninitialized ASN.1 value ("%s" attribute looked up)' % name)
pyasn1.error.PyAsn1Error: Uninitialized ASN.1 value ("len" attribute looked up)

python3 sqlalchemy pymysql connect string

using python3, I can connect to mysql using pymysql. all works as expected. enclosed code works.
import pymysql
conn = pymysql.connect(host='127.0.0.1', unix_socket='/home/jhgong/mysql/tmp/mysql.sock', user='root', passwd='my_pass', db='my_db', port='3333')
cur = conn.cursor()
cur.execute('select user from auth_users')
for i in cur:
print(i)
trying to get sqlalchemy to connect with pymysql, the default example strings don't seem to work. the above example does not work unless I declare both the port number and a unix_socket.
below is what I've been using to try and get sqlalchemy to connect. I assume that the socket and port number are both needed. I used connect_args to feed in a hash with the extra unix_socket location. no joy.
enclosed the the snippit I've been using that creates the error.
conarg = {
'unix_socket':'/home/jhgong/mysql/tmp/mysql.sock',
'db' :'ice'
}
engine = create_engine('mysql+pymysql://root:my_pass#127.0.0.1:3333/my_db', connect_args = conarg, echo=True)
connection = engine.connect()
with or without the db in conarg hash i get the following error:
>>> connection = engine.connect()
2013-01-17 13:04:20,819 INFO sqlalchemy.engine.base.Engine b'SELECT DATABASE()'
2013-01-17 13:04:20,819 INFO sqlalchemy.engine.base.Engine ()
Traceback (most recent call last):
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/pool.py", line 724, in _do_get
return self._pool.get(wait, self._timeout)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/util/queue.py", line 163, in get
raise Empty
sqlalchemy.util.queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/engine/base.py", line 1574, in connect
return self._connection_cls(self, **kwargs)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/engine/base.py", line 58, in __init__
self.__connection = connection or engine.raw_connection()
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/engine/base.py", line 1637, in raw_connection
return self.pool.unique_connection()
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/pool.py", line 182, in unique_connection
return _ConnectionFairy(self).checkout()
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/pool.py", line 398, in __init__
rec = self._connection_record = pool._do_get()
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/pool.py", line 744, in _do_get
con = self._create_connection()
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/pool.py", line 187, in _create_connection
return _ConnectionRecord(self)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/pool.py", line 284, in __init__
exec_once(self.connection, self)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/event.py", line 362, in exec_once
self(*args, **kw)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/event.py", line 379, in __call__
fn(*args, **kw)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/engine/strategies.py", line 168, in first_connect
dialect.initialize(c)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/dialects/mysql/base.py", line 2005, in initialize
default.DefaultDialect.initialize(self, connection)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/engine/default.py", line 183, in initialize
self._get_default_schema_name(connection)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/dialects/mysql/base.py", line 1970, in _get_default_schema_name
return connection.execute('SELECT DATABASE()').scalar()
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/engine/base.py", line 645, in execute
params)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/engine/base.py", line 791, in _execute_text
statement, parameters
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/engine/base.py", line 854, in _execute_context
context)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/SQLAlchemy-0.8.0b1dev-py3.2.egg/sqlalchemy/engine/default.py", line 342, in do_execute
cursor.execute(statement, parameters)
File "/nfs/site/home/jhgongx/.local/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/cursors.py", line 105, in execute
query = query % escaped_args
TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple'
it appears to be raising an error on empty pool queue. setting the size or type of pool queue has no effect.
any suggestions on how to figure this out?
Try this very simple example:
import sqlalchemy
from sqlalchemy.sql import select
from sqlalchemy import Table, MetaData
def init():
try:
server = 'xx'
db = 'xx'
login = 'xx'
passwd = 'xx'
engine_str = 'mysql+mysqlconnector://{}:{}#{}/{}'.format(login, passwd, server, db)
engine = sqlalchemy.create_engine(engine_str, echo=False, encoding='utf-8')
connection = engine.connect()
metadata = MetaData()
t_servers = Table('your_table_here', metadata, autoload=True, autoload_with=engine)
s = select([t_servers])
result = connection.execute(s)
for row in result:
print(row['the_field'])
except Exception:
raise
finally:
connection.close()
if __name__ == '__main__':
init()
Mysql connector for Python 3 : download here
I know this is late but the PyMySQL requirements mention CPython >= 2.6 or >= 3.3, it looks like you're using CPython 3.2 (the default version of python used), and that may be your problem.

Resources