Django Dynamic models throws programming error - python-3.x

I use django-dynamic-model 0.1.0 for dynamic modelling in django.
I have already tried reverting the migrations, changing db. But nothing seems to work.
models.py:
from dynamic_models.models import AbstractModelSchema, AbstractFieldSchema
class ModelSchema(AbstractModelSchema):
pass
class FieldSchema(AbstractFieldSchema):
pass
views.py:
car_model_schema = ModelSchema.objects.create(name='Car')
I face error while creating ModelSchema object:
Internal Server Error: /api/v1.0/boilerplate_apps/graph/
Traceback (most recent call last):
File "/home/ubox72/Extras/graph/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "dynamic_models_modelfieldschema" does not exist
LINE 1: ...ynamic_models_modelfieldschema"."max_length" FROM "dynamic_m...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/ubox72/Extras/graph/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
.......
django.db.utils.ProgrammingError: relation "dynamic_models_modelfieldschema" does not exist
LINE 1: ...ynamic_models_modelfieldschema"."max_length" FROM "dynamic_m...

Trying running this migration as well
python manage.py makemigrations dynamic_models
And then,
python manage.py migrate dynamic_models
This should solve this issue.

Related

Getting psycopg.ProgrammingError: invalid connection option "database" when pasing database parameter

Hey I am new to Databases and I decided to use Postgresql for convinience. And I am using an adapter for the Python programming language of the database named Psycopg I followed the installation tutorial of Psycopg2 but I was getting an error so I decided to install psycopg3 and it installed successfully! but when I pass the database parametere I get the following error:
Traceback (most recent call last):
File "C:\Users\Aditya\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg\conninfo.py", line 97, in _parse_conninfo
return pq.Conninfo.parse(conninfo.encode())
File "psycopg_binary\\pq/conninfo.pyx", line 30, in psycopg_binary.pq.Conninfo.parse
psycopg.OperationalError: invalid connection option "database"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\Aditya\Desktop\Aditya\TGbot\dbhelper.py", line 3, in <module>
conn = psycopg.connect(
File "C:\Users\Aditya\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg\connection.py", line 561, in connect
conninfo = make_conninfo(**params)
File "C:\Users\Aditya\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg\conninfo.py", line 56, in make_conninfo
_parse_conninfo(conninfo)
File "C:\Users\Aditya\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg\conninfo.py", line 99, in _parse_conninfo
raise e.ProgrammingError(str(ex))
psycopg.ProgrammingError: invalid connection option "database"
But when i didnt pass the database argument i didnt get any kind of error... here's my code:
import psycopg
conn = psycopg.connect(
host="localhost",
database="suppliers",
user="postgres",
password="pas")
What i am doing wrong here? I am sure that the i have created the database with that name and the password is also correct.
You look to be using psycopg3. database was a deprecated parameter in psycopg2 and not allowed in psycopg3. You will need to use dbname per the list here as found in page in the psycopg3 page for connect.

_tkinter.TclError: invalid command name ".!text"

I am making a program using tkinter that executes some code from different files.
This is the part of my code causing problems:
text=textbox.get('1.0','end-1c')
FYI: textbox is a tkinter.Text object defined by a different file that my code executed
when ever I execute my code, I get the error:
Exception in Tkinter callback
Traceback (most recent call last):
File "/anaconda3/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "/Users/iskee/python/programs/atfedit/atf.py", line 98, in save
text=textbox.get('1.0','end-1c')
File "/anaconda3/lib/python3.7/tkinter/__init__.py", line 3246, in get
return self.tk.call(self._w, 'get', index1, index2)
_tkinter.TclError: invalid command name ".!text"
what is going wrong?
That error means that you're trying to access a widget that has been destroyed.

Having trouble catching an exception in python 3

Working with Python 3.7.3, still figuring out how exception handling works.
I'm writing an xmpp bot, using slixmpp. I'm trying to make it so that if it loses connection to the server, it will try to reconnect. There doesn't seem to be any way to do this built in to slixmpp, so I'm write something into my own code to do it.
I've imported slixmpp as xmpp, and using it's send_raw() method to test that we're still connected to the server.
while True:
time.sleep(5) # Send every 5 seconds just for testing purposes
xmpp.send_raw('aroo?')
When I sever the connection to the server, this is what it spits out:
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "testcom.py", line 19, in run
eval(self.thing)()
File "testcom.py", line 28, in check_conn
xmpp.send_raw('aroo?')
File "C:\Program Files\Python37\lib\site-packages\slixmpp\xmlstream\xmlstream.py", line 926, in send_raw
raise NotConnectedError
slixmpp.xmlstream.xmlstream.NotConnectedError
I'm assuming that "NotConnectedError" is the exception that I need to catch, so I put the code inside a try block, like so:
try:
while True:
time.sleep(5) # Send every 5 seconds just for testing purposes
xmpp.send_raw('aroo?')
except NotConnectedError:
# Do a thing
pass
And this is what I get:
Traceback (most recent call last):
File "testcom.py", line 28, in check_conn
xmpp.send_raw('aroo?')
File "C:\Program Files\Python37\lib\site-packages\slixmpp\xmlstream\xmlstream.py", line 926, in send_raw
raise NotConnectedError()
slixmpp.xmlstream.xmlstream.NotConnectedError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
"testcom.py", line 19, in run
eval(self.thing)()
File "testcom.py", line 29, in check_conn
except NotConnectedError:
NameError: name 'NotConnectedError' is not defined
Can anyone tell me what I'm doing wrong here?
Thanks!
I can't see your imports but make sure you have from slixmpp.xmlstream.xmlstream import NotConnectedError otherwise it doesn't have a definition for NotConnectedError within the application. You could also change NotConnectedError to xmpp.xmlstream.xmlstream.NotConnectedError if you don't want to have it imported as well.

python 3 exception also gives the output of the previous program

i ran into an interesting bug when writing a json parser(called /home/myusername/py/json.py) in python3
i raised a basic exception and got unexpected output,
when investigating this further i wrote a new script entirely given below
/home/myusername/py/error.py
raise Exception("basic exception")
after running "python3 error.py"
i should get a really short error message, but instead i get console output of the previous run program.
[unexpected debug output of json.py]
[truncated for readability]
[it is extremely long but does not contain further errors]
Traceback (most recent call last):
File "error.py", line 1, in <module>
raise Exception("basic exception")
Exception: basic exception
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 17, in <module>
import json
File "/home/myusername/py/json.py", line 174, in <module>
rs = parser.Object(testcase)
File "/home/myusername/py/json.py", line 104, in Object
raise Exception(self.Array(source, "crashing object scanner"))
Exception: None
Original exception was:
Traceback (most recent call last):
File "error.py", line 1, in <module>
raise Exception("basic exception")
Exception: basic exception
i dont know why i get such a long message. nor do i know why i get debug code of an uncalled script. i would like an explanation, i am running Ubuntu, i have not yet found related bugs on the internet.
it appears that basic exception handling requires a json.py script, so when my error.py raises an exception it loads my json.py script instead of the buildin script, then my json script trows an exception.
the solution is to rename my json.py

CherryPy Autoloader dies with bcrypt

I have pure project on CherryPy and want AuthTool to use bcrypt module for password processing.
But when I put "import bcrypt" line into AuthTool.py the CherryPy tells me:
[17/Nov/2017:17:55:57] ENGINE Error in background task thread function <bound method Autoreloader.run of <cherrypy.process.plugins.Autoreloader object at 0x0000026948C82E80>>.
AttributeError: cffi library '_bcrypt' has no function, constant or global variable named '__loader__'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Serge\AppData\Local\Programs\Python\Python36\lib\site-packages\cherrypy\process\plugins.py", line 519, in run
self.function(*self.args, **self.kwargs)
File "C:\Users\Serge\AppData\Local\Programs\Python\Python36\lib\site-packages\cherrypy\process\plugins.py", line 651, in run
for filename in self.sysfiles() | self.files:
File "C:\Users\Serge\AppData\Local\Programs\Python\Python36\lib\site-packages\cherrypy\process\plugins.py", line 635, in sysfiles
hasattr(m, '__loader__') and
SystemError: <built-in function hasattr> returned a result with an error set
Exception in thread Autoreloader:
AttributeError: cffi library '_bcrypt' has no function, constant or global variable named '__loader__'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Serge\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\Serge\AppData\Local\Programs\Python\Python36\lib\site-packages\cherrypy\process\plugins.py", line 519, in run
self.function(*self.args, **self.kwargs)
File "C:\Users\Serge\AppData\Local\Programs\Python\Python36\lib\site-packages\cherrypy\process\plugins.py", line 651, in run
for filename in self.sysfiles() | self.files:
File "C:\Users\Serge\AppData\Local\Programs\Python\Python36\lib\site-packages\cherrypy\process\plugins.py", line 635, in sysfiles
hasattr(m, '__loader__') and
SystemError: <built-in function hasattr> returned a result with an error set
After that everithing works fine but Autoloader. I have bcrypt (3.1.4) and CherryPy (11.1.0).
Can I do something to fix this issue this autoreloader? Merci.
You could disable the autoloader. Set 'engine.autoloader.on' to False. Of course you will loose auto loading when monitored files are changed and thus you'll need to manually restart the server on each change. Another way would be to put the server in production mode. See available mode and what they do at: http://docs.cherrypy.org/en/latest/config.html#id14
BTW: I am seeing a similar issue with cherrypy (13.0.0) and cryptography (2.1.4)

Resources