PyOrient SQL Query MemoryError - python

I have to read from a OrientDB. To test that everything works I tried to read from the Database with the SELECT Statement.
like this:
import pyorient
client = pyorient.OrientDB("adress", 2424)
session_id = client.connect("root", "password")
client.db_open("table","root","password")
print str(client.db_size())
client.query("SELECT * FROM L1_Req",1)
The Connection works fine and also the print str(client.db_size()) line.
But at client.query("SELECT * FROM L1_Req",1) it returns the following Error Message:
Traceback (most recent call last):
File "testpy.py", line 9, in <module>
client.query("SELECT * FROM L1_Req",1)
File "C:\app\tools\python27\lib\site-packages\pyorient\orient.py", line 470, i
n query
.prepare(( QUERY_SYNC, ) + args).send().fetch_response()
File "C:\app\tools\python27\lib\site-packages\pyorient\messages\commands.py",
line 144, in fetch_response
super( CommandMessage, self ).fetch_response()
File "C:\app\tools\python27\lib\site-packages\pyorient\messages\base.py", line
265, in fetch_response
self._decode_all()
File "C:\app\tools\python27\lib\site-packages\pyorient\messages\base.py", line
249, in _decode_all
self._decode_header()
File "C:\app\tools\python27\lib\site-packages\pyorient\messages\base.py", line
176, in _decode_header
serialized_exception = self._decode_field( FIELD_STRING )
File "C:\app\tools\python27\lib\site-packages\pyorient\messages\base.py", line
366, in _decode_field
_decoded_string = self._orientSocket.read( _len )
File "C:\app\tools\python27\lib\site-packages\pyorient\orient.py", line 164, i
n read
buf = bytearray(_len_to_read)
MemoryError
I also tried some ohter SQL Statements like:
client.query("SELECT subSystem FROM L1_Req",1)
I cant't get why this happends. Can you guys help me ?

Related

Locust put request is randomly failing

My locust file has put requests but sometimes it's passing sometimes failing. Can anyone explain why that's happening?
Here is my locust file
def _generate_put_data(self) -> str:
if len(self.ids) > 0:
teacher_name = self.generate_random_string()
teacher_email = f"{self.generate_random_string()}#{self.generate_random_string()}.{self.generate_random_string()}"
teacher_email = teacher_email.replace("#", "%40")
teacher_id = str(random.choice(self.ids))
request_string = f"{self.path_all}/{teacher_id}?teacherName={teacher_name}&teacherEmail={teacher_email}"
return request_string
#task(2)
def put_request(self):
self.client.put(url=self._generate_put_data())
...
_generate_put_data method returns a string, which is a query.
Here is the error:
[2023-01-26 11:39:12,357] pop-os/ERROR/locust.user.task: expected string or bytes-like object
Traceback (most recent call last):
File "/home/XXX/.local/lib/python3.10/site-packages/locust/user/task.py", line 347, in run
self.execute_next_task()
File "/home/XXX/.local/lib/python3.10/site-packages/locust/user/task.py", line 372, in execute_next_task
self.execute_task(self._task_queue.pop(0))
File "/home/XXX/.local/lib/python3.10/site-packages/locust/user/task.py", line 493, in execute_task
task(self.user)
File "/home/XXX/Desktop/my-projects/spring-boot-app/performans-testing/locust.py", line 44, in put_request
self.client.put(url=self._generate_put_data())
File "/home/XXX/.local/lib/python3.10/site-packages/requests/sessions.py", line 647, in put
return self.request("PUT", url, data=data, **kwargs)
File "/home/XXX/.local/lib/python3.10/site-packages/locust/clients.py", line 131, in request
url = self._build_url(url)
File "/home/XXX/.local/lib/python3.10/site-packages/locust/clients.py", line 81, in _build_url
if absolute_http_url_regexp.match(path):
TypeError: expected string or bytes-like object

How to read Interbase database with Cyrillic text content

I am using pyfirebirdsql version 0.8.5 to connect to Interbase database.
import firebirdsql
conn = firebirdsql.connect(
host='192.168.133.121',
database='E:\\test\test.gdb',
port=3050,
user='sysdba',
password='masterkey'
#charset="WIN1251"
#charset="UTF8"
)
cur = conn.cursor()
cur.execute("select column1 from table1")
for c in cur.fetchall():
print(c)
conn.close()
When I try to run the script I get the following:
Traceback (most recent call last):
File "123.py", line 15, in <module>
for c in cur.fetchall():
File "/usr/lib/python2.7/site-packages/firebirdsql/fbcore.py", line 291, in fetchall
return [tuple(r) for r in self._fetch_records]
File "/usr/lib/python2.7/site-packages/firebirdsql/fbcore.py", line 225, in _fetch_generator
stmt_handle, self._xsqlda)
File "/usr/lib/python2.7/site-packages/firebirdsql/wireprotocol.py", line 728, in _op_fetch_response
return self._parse_op_response() # error occured
File "/usr/lib/python2.7/site-packages/firebirdsql/wireprotocol.py", line 210, in _parse_op_response
raise OperationalError(message, gds_codes, sql_code)
firebirdsql.OperationalError: arithmetic exception, numeric overflow, or string truncation
Cannot transliterate character between character sets
Adding charset both "WIN1251" and "UTF8" doesn't solve the issue. Do you have any ideas?

neomodel giving Attribute error on save

I am running the following config for neo4j:
neo4j - 3.0.0
py2neo - 2.0.8
neomodel - 2.0.2
Finally, the code I try to run is:
class User(neomodel.StructuredNode):
user_id = neomodel.IntegerProperty(unique_index=True, required=True)
name = neomodel.StringProperty()
phone_number = neomodel.StringProperty()
user = User(user_id=6, name='Sourabh Dev', phone_number='9711237840').save()
I don't understand, why I keep getting this strange error. Am I doing something wrong here or should I use py2neo instead of neomodel?
My traceback is:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python3.4/site-packages/neomodel-2.0.2-py3.4.egg/neomodel/signals.py", line 25, in hooked
val = fn(self, *args, **kwargs)
File "/usr/local/lib/python3.4/site-packages/neomodel-2.0.2-py3.4.egg/neomodel/core.py", line 159, in save
self._id = self.create(self.__properties__)[0]._id
File "/usr/local/lib/python3.4/site-packages/neomodel-2.0.2-py3.4.egg/neomodel/core.py", line 289, in create
results = db.cypher_query(query, params)
File "/usr/local/lib/python3.4/site-packages/neomodel-2.0.2-py3.4.egg/neomodel/util.py", line 213, in cypher_query
results = self._execute_query(query, params)
File "/usr/local/lib/python3.4/site-packages/neomodel-2.0.2-py3.4.egg/neomodel/util.py", line 207, in _execute_query
results = self.session.cypher.execute(query, create_params=params)
File "/usr/local/lib/python3.4/site-packages/py2neo/cypher/core.py", line 136, in execute
results = tx.commit()
File "/usr/local/lib/python3.4/site-packages/py2neo/cypher/core.py", line 333, in commit
return self.post(self.__commit or self.__begin_commit)
File "/usr/local/lib/python3.4/site-packages/py2neo/cypher/core.py", line 288, in post
raise self.error_class.hydrate(error)
File "/usr/local/lib/python3.4/site-packages/py2neo/cypher/error/core.py", line 54, in hydrate
error_cls = getattr(error_module, title)
AttributeError: 'module' object has no attribute 'TypeError'
Two points here:
Existing Neomodel doesn't support the Neo4j 3.0
Cypher syntax has changed in 3.0, so the error raises.
In 2.x , MATCH n RETURN n
In 3.0 , MATCH (n) RETURN n
Node n is enclosed in braces.

pymssql bulk insert error (python)

Trying to bulk insert a CSV file using pymssql here's the code:
conn = pymssql.connect(host='server', user='user', password='secret', database='My_Dev')
cur = conn.cursor()
load = 'BULK INSERT TempStaging FROM \'/home/dross/python/scripts/var/csv/' + f + '.csv\' WITH (FIRSTROW = 1,FIELDTERMINATOR = ',',ROWTERMINATOR = \'\\n\') GO")'
cur.execute(load)
When executing get following error:
Traceback (most recent call last):
File "./uploadResults.py", line 46, in <module>
cur.execute(sweepload)
File "pymssql.pyx", line 447, in pymssql.Cursor.execute (pymssql.c:7092)
File "_mssql.pyx", line 1009, in _mssql.MSSQLConnection.execute_query (_mssql.c:11585)
File "_mssql.pyx", line 1040, in _mssql.MSSQLConnection.execute_query (_mssql.c:11459)
File "_mssql.pyx", line 1160, in _mssql.MSSQLConnection.format_and_run_query (_mssql.c:12652)
File "_mssql.pyx", line 203, in _mssql.ensure_bytes (_mssql.c:2733)
AttributeError: 'tuple' object has no attribute 'encode'
Line 46 is cur.execute line
Note that .format() could allow sql injection, but if you control the filename then it's not that bad (not sure if a parameter would work here).
Also, you should use triple-quoted strings when dealing with SQL, your life will be so much better. Like this:
load = '''BULK INSERT TempStaging FROM /home/dross/python/scripts/var/csv/{}.csv WITH (FIRSTROW=1, FIELDTERMINATOR=',', ROWTERMINATOR='\n')'''.format(filename)
Being triple quoted, you can also break it up to make it easier to read:
load = '''
BULK INSERT TempStaging
FROM /home/dross/python/scripts/var/csv/{}.csv
WITH (
FIRSTROW=1
, FIELDTERMINATOR=','
, ROWTERMINATOR='\n'
)
'''.format(filename)
You should defined the string as below:
load = "BULK INSERT TempStaging FROM /home/dross/python/scripts/var/csv/" + f + ".csv WITH ( FIRSTROW=1 , FIELDTERMINATOR=',' , ROWTERMINATOR='\\n')"

Tuleap LDAP Subversion Browse Svn Tree Issue

I have enabled LDAP on tuleap. But when I go to subversion> Browse SVN tree, I get following error
An Exception Has Occurred
Python Traceback
Traceback (most recent call last): File
"/usr/share/viewvc/lib/viewvc.py", line 3814, in main
request.run_viewvc() File "/usr/share/viewvc/lib/viewvc.py", line 318, in run_viewvc
if not svnaccess.check_read_access(user.user_getname(), self.rootpath, self.where): File
"/usr/share/tuleap/src/www/../utils/svn/svnaccess.py", line 130, in
check_read_access
username = get_name_for_svn_access(svnrepo, username) File "/usr/share/tuleap/src/www/../utils/svn/svnaccess.py", line 119, in
get_name_for_svn_access
return codendildap.get_login_from_username(username) File "/usr/share/tuleap/src/www/../utils/svn/codendildap.py", line 60, in
get_login_from_username
return get_login_from_eduid(row['ldap_id']) File "/usr/share/tuleap/src/www/../utils/svn/codendildap.py", line 43, in
get_login_from_eduid
l = ldap_connect() File "/usr/share/tuleap/src/www/../utils/svn/codendildap.py", line 33, in
ldap_connect
l = ldap.initialize(server) File "/usr/lib64/python2.6/site-packages/ldap/functions.py", line 85, in
initialize
return LDAPObject(uri,trace_level,trace_file,trace_stack_limit) File "/usr/lib64/python2.6/site-packages/ldap/ldapobject.py", line
69, in __init__
self._l = ldap.functions._ldap_function_call(_ldap.initialize,uri) File
"/usr/lib64/python2.6/site-packages/ldap/functions.py", line 57, in
_ldap_function_call
result = func(*args,**kwargs) LDAPError:(0, 'Error')
$sys_ldap_server = 'X.X.X.X:xxx'; $sys_ldap_cn='cn'; $sys_ldap_people_dn='ou=Users,dc=xxxx,dc=org'; $sys_ldap_search_user='(|(uid=%words%)(cn=%words%))'; $sys_ldap_default_user_status='A'; $sys_ldap_svn_auth=1; $sys_ldap_daily_sync=1; $sys_ldap_user_management=1; $sys_ldap_grp_enabled = 1; $sys_ldap_grp_dn='ou=groups,dc=xxxx,dc=org'; $sys_ldap_grp_cn = 'cn'; $sys_ldap_grp_member='uniquemember';
The LDAP server configuration variable should be defined with ldap:// (or ldaps:// for SSL LDAP)

Categories

Resources