I am trying to connect to a firebird super server.I have the fdb package installed.
I am trying
from sqlalchemy import create_engine
engine = create_engine ('localhost:c:\fdbb\school.fdb')
I get this error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build\bdist.win32\egg\sqlalchemy\engine\__init__.py", line 332, in creat
e_engine
File "build\bdist.win32\egg\sqlalchemy\engine\strategies.py", line 48, in crea
te
File "build\bdist.win32\egg\sqlalchemy\engine\url.py", line 154, in make_url
File "build\bdist.win32\egg\sqlalchemy\engine\url.py", line 196, in _parse_rfc
1738_args
sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string 'localhost
:c:♀dbb\school.fdb'
Am i doing this right?.
Solved it this way
import sqlalchemy
import fdb
engine =
create_engine('firebird+fdb://sysdba:masterkey#localhost:3050/c:/fdbb/school.fdb')
Related
I installed chatterbot in my terminal earlier today using virtual studio code's terminal. I saw that both chatterbot and chatterbot_corpus worked in installation. Then, I made the following python document:
EDIT: Turns out I should define a chatbot variable first.
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.trainers import ListTrainer
conversation = [
"Hello",
"Hi there!",
"How are you doing?",
"I'm doing great.",
"That is good to hear",
"Thank you.",
"You're welcome."
]
bot = ChatBot('Maya')
trainer = ListTrainer(bot)
trainer.train(conversation)
This was my code
it says this however
bot = ChatBot('Maya')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 22, in __init__
from sqlalchemy import create_engine
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\__init__.py", line 8, in <module>
from . import util as _util # noqa
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\__init__.py", line 14, in <module>
from ._collections import coerce_generator_arg # noqa
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\_collections.py", line 16, in <module>
from .compat import binary_types
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
Does anyone know how to fix this easily?
EDIT: I just updated python using pip install --upgrade ipython in terminal, but it didn't fix the issue
EDIT 2: Well now I tried updating a package using pip install sqlalchemy --upgrade
But now it gives
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 46, in __init__
if not self.engine.dialect.has_table(self.engine, 'Statement'):
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\dialects\sqlite\base.py", line 2009, in has_table
self._ensure_has_table_connection(connection)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\engine\default.py", line 341, in _ensure_has_table_connection
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: The argument passed to Dialect.has_table() should be a <class 'sqlalchemy.engine.base.Connection'>,
got <class 'sqlalchemy.engine.base.Engine'>. Additionally, the Dialect.has_table() method is for internal dialect use only; please use ``inspect(some_engine).has_table(<tablename>>)`` for public API use.
I am in the latest version though
PS C:\Users\Subha> Python --version
Python 3.9.6
EDIT 3: Now it comes up with
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 46, in __init__
# if not self.engine.dialect.has_table(self.engine, 'Statement'):
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\dialects\sqlite\base.py", line 2009, in has_table
self._ensure_has_table_connection(connection)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\engine\default.py", line 341, in _ensure_has_table_connection
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: The argument passed to Dialect.has_table() should be a <class 'sqlalchemy.engine.base.Connection'>, got <class 'sqlalchemy.engine.base.Engine'>. Additionally, the Dialect.has_table() method is for internal dialect use only; please use ``inspect(some_engine).has_table(<tablename>>)`` for public API use.
it seems the python upgrade worked with regard to the initial error on time.clock. This new error you are seeing is quite different to the previous one. In this case you need to go into chatterbot/storage/sql_storage.py and comment out if not self.engine.dialect.has_table(self.engine, 'Statement'): and leave only self.create_database(). This means that instead of checking whether a database table has been created which is triggering the error, it will just create the DB every time, which i expect to work fine.
# if not self.engine.dialect.has_table(self.engine, 'Statement'):
self.create_database()
I wrote the following program to connect to my mongo database
from flask import Flask
from flask_mongoalchemy import MongoAlchemy
app = Flask(__name__)
app.config['MONGOALCHEMY_DATABASE']='MyDatabase'
app.config['MONGOALCHEMY_CONNECTION_STRING']='mongodb://<username>:<password>#mycluster-shard-00-00-cfkbg.mongodb.net:27017,mycluster-shard-00-01-cfkbg.mongodb.net:27017,mycluster-shard-00-02-cfkbg.mongodb.net:27017/test?ssl=true&replicaSet=MyCluster-shard-0&authSource=admin&retryWrites=true&w=majority'
db=MongoAlchemy(app)
class Example(db.Document):
name=db.StringField()
if __name__=='__main__':
obj=Example(name='Aman')
obj.save()
Error:
Traceback (most recent call last):
File "app.py", line 15, in <module>
obj.save()
File "/usr/local/lib/python3.6/dist-packages/flask_mongoalchemy/__init__.py", line 271, in save
self._session.insert(self, safe=safe)
File "/usr/local/lib/python3.6/dist-packages/mongoalchemy/session.py", line 172, in insert
self.add(item, safe=safe)
File "/usr/local/lib/python3.6/dist-packages/mongoalchemy/session.py", line 188, in add
return self.flush()
File "/usr/local/lib/python3.6/dist-packages/mongoalchemy/session.py", line 414, in flush
result = op.execute()
File "/usr/local/lib/python3.6/dist-packages/mongoalchemy/ops.py", line 97, in execute
return self.collection.save(self.data, safe=self.safe)
File "/usr/local/lib/python3.6/dist-packages/pymongo/collection.py", line 1881, in save
write_concern = WriteConcern(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'safe'
Try to install an older version of pymongo (preferably 2.9.0).
According to https://github.com/MongoEngine/mongoengine/issues/1154:
last version of mongoengine is not compatible with pymongo 3+:
I am trying to execute following code but it is not running. Error log pasted below. This issue is caused may be because of importing PG but I don't know how to resolve this.
import pandas as pd
from sqlalchemy import create_engine, MetaData, Table, select, engine
from sqlalchemy.orm import sessionmaker
import datetime
import cx_Oracle
import dateutil.relativedelta
import configparser
import sys, os
from boto3.s3.transfer import S3Transfer
import boto3
import pg
try:
options = 'keepalives=1 keepalives_idle=200 keepalives_interval=200 keepalives_count=5'
connection_string = "host=%s port=%s dbname=%s user=%s password=%s %s" % (
'somehost', '8192', 'somedb', 'someuser', 'somepassword', options)
print(connection_string)
con = pg.connect(dbname=connection_string)
print('Connected to Redshift.Connection Detail : %s' % con)
except Exception as e:
print('Unable to Connect to Redshift')
print(e.message)
print('No')
sys.exit(1)
C:\Users\olaa\Desktop\CWB> python .\my.py Traceback (most recent call last): File ".\my.py", line 11, in <module>
import pg File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\site-packages\pg\__init__.py", line 1, in <module>
from .core import ( File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\site-packages\pg\core.py", line 6, in <module>
from . import glfw File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\site-packages\pg\glfw.py", line 138, in <module>
['', '/usr/lib', '/usr/local/lib', 'C:/Users/olaa/AppData/Local/Programs/Python/Python36/Lib/site-packages/pg/'],
_g lfw_get_version) File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\site-packages\pg\glfw.py", line 74, in _load_library
version = version_check_callback(filename) File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\site-packages\pg\glfw.py", line 130, in _glfw_get_versi on
out = process.communicate(_to_char_p(filename))[0] File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 836, in communicate
stdout, stderr = self._communicate(input, endtime, timeout) File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 1076, in _communicate
self._stdin_write(input) File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 776, in _stdin_write
self.stdin.write(input) TypeError: write() argument must be str, not bytes
Traceback (most recent call last):
File "<string>", line 28, in <module>
EOFError: EOF when reading a line
import pg
This isn't a Postgres library. It's an OpenGL graphics library
Even if that import worked, it would fail at con = pg.connect(...
You're trying to connect to Redshift / Postgres, so try one of the actual Postgres clients
In general, Python users want to use psycopg2 unless they have a strong reason to try another driver
https://wiki.postgresql.org/wiki/Python
from pyhive import hive
import thrift_sasl
connection = hive.Connection(host='myhost', port=10000, database='local')
#hangs here
from sqlalchemy import create_engine
engine = create_engine('hive://myhost:10000/local')
logs = Table('mytable', MetaData(bind=engine), autoload=True)
#also hangs here
Both of these snippets will hang for me.
Hitting ctrl+c stops the execution here:
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/apps/Python/lib/python2.7/site-packages/pyhive/hive.py", line 86, in __init__
self._transport.open()
File "thrift_sasl.py", line 74, in open
status, payload = self._recv_sasl_message()
File "thrift_sasl.py", line 92, in _recv_sasl_message
header = self._trans.readAll(5)
File "/apps/Python/lib/python2.7/site-packages/thrift/transport/TTransport.py", line 58, in readAll
chunk = self.read(sz - have)
File "/apps/Python/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 105, in read
buff = self.handle.recv(sz)
KeyboardInterrupt
I am using Hive 0.12 and HiveServer2. I can connect to it using the python Hive library provided with Hadoop (.../hive/lib/py) but cannot do so with pyhive, which uses thrift_sasl.
Some people not using the thrift_sasl module suggest turning off SASL support in hive-site.xml via:
<property><name>hive.server2.authentication</name><value>NOSASL</value></property>
However after trying this the code still hanged with the same stack trace when I issued a KeyboardInterrupt.
When I try to load http://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl the exception Type not found: '(IPAddressFilter, http://www.onvif.org/ver10/schema/onvif.xsd, )' raises. Is it possible to fix?
from suds.client import Client
client = Client('file:///home/web/www/wsdl/devicemgmt.wsdl')
P.S. WSDL file changed by me, just added direct link to the http://www.onvif.org/ver10/schema/onvif.xsd in the start of the file.
P.P.S
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/suds/client.py", line 119, in __init__
sd = ServiceDefinition(self.wsdl, s)
File "/usr/local/lib/python2.7/dist-packages/suds/servicedefinition.py", line 58, in __init__
self.paramtypes()
File "/usr/local/lib/python2.7/dist-packages/suds/servicedefinition.py", line 137, in paramtypes
item = (pd[1], pd[1].resolve())
File "/usr/local/lib/python2.7/dist-packages/suds/xsd/sxbasic.py", line 63, in resolve
raise TypeNotFound(qref)
suds.TypeNotFound: Type not found: '(IPAddressFilter, http://www.onvif.org/ver10/schema/onvif.xsd, )'
Try adding schema to import.
from suds.client import Client
from suds.xsd.doctor import ImportDoctor
from suds.xsd.doctor import Import
imp = Import('http://www.w3.org/2001/XMLSchema') # the schema to import.
imp.filter.add('http://www.onvif.org/ver10/schema') # the schema to import into.
d = ImportDoctor(imp)
s = Client("http://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl", doctor = d)