bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- /dbs/supermodels.db: unexpected file type or format')
Is this error a result of incompatible BDB versions (1.85 or 3+)? If so, how do I check the versions, trouble-shoot and solve this error?
Yes, this certainly could be due to older versions of the db file, but it would help if you posted the code that generated this exception and the full traceback.
In the absence of this, are you sure that the database file that you're opening is of the correct type? For example, attempting to open a btree file as if it is a hash raises the exception that you are seeing:
>>> import bsddb
>>> bt = bsddb.btopen('bt')
>>> bt.close()
>>> bsddb.hashopen('bt')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/bsddb/__init__.py", line 298, in hashopen
d.open(file, db.DB_HASH, flags, mode)
bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- ./bt: unexpected file type or format')
In *nix you can usually determine the type of db by using the file command, e.g.
$ file /etc/aliases.db cert8.db
/etc/aliases.db: Berkeley DB (Hash, version 8, native byte-order)
cert8.db: Berkeley DB 1.85 (Hash, version 2, native byte-order)
Opening a 1.85 version file fails with the same exception:
>>> db = bsddb.hashopen('/etc/aliases.db') # works, but...
>>> db = bsddb.hashopen('cert8.db')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/bsddb/__init__.py", line 298, in hashopen
d.open(file, db.DB_HASH, flags, mode)
bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- ./cert8.db: unexpected file type or format')
If you need to migrate the database files, you should look at the db_dump, db_dump185 and db_load utilities that come with the bdb distribuition.
Related
I'm using nxt-python to connect to my nxt brick from my raspberry pi.
After some struggle with the python 3.2 versions of the bluetooth and usb libraries it requires i've managed to get it to connect via bluetooth and ask for a passkey. After some more struggle i found that i could type bluetooth-agent PASSKEY & (and replace PASSKEY with the passkey) in the terminal before running the python script that connects with the nxt brick and as far as i know that works fine. But now it throws an error. Connecting with USB throws a different error.
Here's the error i get with both methods (USB & BT) and debug enabled:
USB: True BT: True Fantom: False FUSB: False FBT: False
Traceback (most recent call last):
File "/usr/local/lib/python3.2/dist-packages/nxt/locator.py", line 138, in find_one_brick
if name and info[0].strip('\0') != name:
TypeError: Type str doesn't support the buffer API
Failed to connect to possible brick
Traceback (most recent call last):
File "/usr/local/lib/python3.2/dist-packages/nxt/locator.py", line 131, in find_one_brick
info = b.get_device_info()
File "/usr/local/lib/python3.2/dist-packages/nxt/brick.py", line 27, in poll
self.sock.send(ogram.bytes())
File "/usr/local/lib/python3.2/dist-packages/nxt/bluesock.py", line 57, in send
l0 = len(data.encode('utf-8')) & 0xFF
AttributeError: 'bytes' object has no attribute 'encode'
Failed to connect to possible brick
No brick was found.
Is the brick turned on?
For more diagnosing use the debug=True argument or
try the 'nxt_test' script located in /bin or ~/.local/bin
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.2/dist-packages/nxt/locator.py", line 154, in find_one_brick
raise BrickNotFoundError
nxt.locator.BrickNotFoundError
Because i know python i could probably fix the errors by just editing the source code, but i'm affraid i'll break something. I've tried editing it (keeping backups of every file i edit) and then it gets past a couple of lines before throwing another different error.
EDIT
When i try to import using python 2 it gives me this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nxt/__init__.py", line 15, in <module>
from nxt.locator import find_one_brick, Method
File "/usr/local/lib/python2.7/dist-packages/nxt/locator.py", line 49
if not silent: print("USB module unavailable, not searching there", file=sys.stderr)
^
SyntaxError: invalid syntax
I've downloaded the v2.2.2 stable instead of cloning the master commit and it runs fine under python2. Too bad it isn't python3 though.
My final purpose is to convert a running Python project to Jython interpreter because some java API's are going to be added.
Details:
The latest Jython is 2.7
The project I have is runnable with Python 3.5
So I took the following approach:
First thing was to convert my project to Python 2.7 utilizing the future module and pasteurize executable.
This step was done successfully.
Second thing is to convert the Python 2.7 project to a Jython 2.7 Project.
Switching the interpreter at Eclipse mars, the following error was indicated:
console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
To workaround it, the solution from this post was utilized by passing the encoding argument -Dpython.console.encoding=UTF-8 to the java VM according to figure below:
Thumbs were up when trying to run again. But unfortunately here, the error shown below just appeared. As I don't plan to change any imported module if there's no need to do so, I decided to ask help here.
pydev debugger: starting (pid: 4216)
Traceback (most recent call last):
File "C:\Users\souzadan\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\pydevd.py", line 2364, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Users\souzadan\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\pydevd.py", line 1784, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Users\souzadan\FirmwareDevTools\Workspaces\Eclipse\aPythonWorkspace\aPythonProject\aPythonFolder\aPythonFile.py", line 7, in <module>
standard_library.install_aliases()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\standard_library\__init__.py", line 465, in install_aliases
from future.backports.urllib import request
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\urllib\request.py", line 96, in <module>
from future.backports import email
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\email\__init__.py", line 16, in <module>
from future.utils import surrogateescape
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 167, in <module>
FS_ENCODING = 'ascii'; fn = b('[abc\xff]'); encoded = u('[abc\udcff]')
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 25, in u
return text.decode('unicode_escape')
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 4-10: illegal Unicode character
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 297, in _MainThread__exitfunc
t.join()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 128, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
Error in sys.exitfunc:
Traceback (most recent call last):
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 297, in _MainThread__exitfunc
t.join()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 128, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
Running Jython through the command line results in a shorter error log:
Traceback (most recent call last):
File "somePythonCode.py", line 7, in <module>
standard_library.install_aliases()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\standard_library\__init__.py", line 465, in install_aliases
from future.backports.urllib import request
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\urllib\request.py", line 96, in <module>
from future.backports import email
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\email\__init__.py", line 16, in <module>
from future.utils import surrogateescape
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 167, in <module>
FS_ENCODING = 'ascii'; fn = b('[abc\xff]'); encoded = u('[abc\udcff]')
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 25, in u
return text.decode('unicode_escape')
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 4-10: illegal Unicode character
Does anybody have a clue of how to solve this error in the most elegant manner?
A bug was created at Jython.org with a critical severity because many people are utilizing already the latest Python modules and interpreter. And they might want to add Java functionality to their code. So they would basically have to take same path as I did. Backporting the project to Python 2.7 then to Jython 2.7 subsequentely.
At python-future a feature request bug was recorded too.
Relying on py4j, as Roland Smith suggests, would be a good approach for porting your app to a JVM environment.
I was looking for some help with a program I am writing for personal use. It is supposed to export a movie's name and rating (stored in a dictionary) to an external file (file.txt) and then load it at the start of every run. It should also export a movie's name and review (also a dictionary) to another external file (review.txt). I get an error on the line for reading the file.txt and putting it in base. Any clues?
base = {}
#Open and write info to base
with open('file.txt','r') as f:
# Error here :(
base = eval(f.read())
error message:
Traceback (most recent call last):
File "/Users/Will/Documents/movie_database.py", line 18, in <module>
base = eval(f.read())
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
Your file is empty, so eval() throws an exception because no Python expression was found:
>>> eval('') # empty string
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
You shouldn't be using eval() in the first place however, the security implications are terrifying here. Someone that can fool you into loading an arbitrary file can now take over your Python process, and turn your machine into a spam bot zombie.
json or shelve (or directly using pickle, although that has security implications as well) would offer you better and more robust serialisation options. You could also look into using sqlite3 for a SQL database option.
I want to use a Berkeley DB in the concurrent read mode, so in a python interpreter (Python 2.7.8 64-bit on Win7) I did this:
import os
from bsddb import db
os.chdir(os.path.expanduser('~'))
os.mkdir('DB')
home_dir = os.path.join(os.getcwd(), 'DB')
dbenv = db.DBEnv()
dbenv.open(home_dir, db.DB_INIT_CDB|db.DB_INIT_MPOOL, 0)
which gives me this error
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
dbenv.open(home_dir, db.DB_INIT_CDB|db.DB_INIT_MPOOL, 0)
DBNoSuchFileError: (2, 'No such file or directory')
What am I doing wrong?
When opening a database for the first time, specify the DB_CREATE flag in addition to the others you've listed.
I am reading the bottle source code and see:
eval(compile('def _raise(*a): raise a[0], a[1], a[2]', '<py3fix>', 'exec'))
I read the documentation about compile and it only tells me that <string> is commonly used. I also googled and searched on stackoverflow but can not find the related info.
So can anyone tell me how <py3fix> affects compilation? And is there any other filename, where can I find the related documentation?
Thanks in advance.
It doesn't affect it at all. It's just a name that it's used to identify where the compiled code is coming from, so you can use string you want.
Like the docs say:
compile(source, filename, mode[, flags[, dont_inherit]])
The filename argument should give the file from which the code was
read; pass some recognizable value if it wasn’t read from a file
('< string>' is commonly used).
in the case where the source is not being read from a file (like here) they suggest that you use <string> so that you know that this code is compiled from a written string.
The person who comited the code, did it when fixing some Bottle Python 2/3 bugs. So I'm guessing that he used <py3fix> as a way to identify the assertion was raised from the def _raise he compiles when the user is running 2.x:
>>> eval(compile('def _raise(*a): raise a[0], a[1], a[2]', '<py3fix>', 'exec'))
>>> _raise(Exception, "error message", None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<py3fix>", line 1, in _raise
Exception: error message
>>> eval(compile('def _raise(*a): raise a[0], a[1], a[2]', '<my_source_file>', 'exec'))
>>> _raise(Exception, "error message", None)Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<my_source_file>", line 1, in _raise
Exception: error message