When running psycopg2.connect as follows:
connection = psycopg2.connect(dbname="learning", user="postgres",
password="xxxxx", host="localhost", port="5434")
I get "database does not exist":
File "<pyshell#10>", line 1, in <module>
--// function from above) //---
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/
site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: database "learning" does not exist
However, if I point to "postgres" (i.e. same code, dbname="postgres") the command yields no errors.
Understanding that the postgres DB has special functionality, I am unable to find any overt differences in the settings for postgres and learning, other than that the activity status for postgres is "active", whereas the activity status for "learning" is idle.
Any recommendations how to fix the connection problem appreciated!
Details: python 3.6.5, pagadmin4, postgreSQL(10), MacOSX 10.13.3. *My install of psycopg2 yielded a warning about the wheel package. Happy to share if relevant.
Related
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.
Python 3.6.4 (32 bit x86) using slackclient locally connects to the RTM API and is able to listen in on slack channel changes. That same code running in Azure (64 bit AMD) does not work.
I've made sure that the Azure python install is as close to my local machine as possible. There are a few package discrepancies (see below) though this should not be the issue since these are not being used:
Azure vs. Local Machine
* numpy 1.15.3 vs. numpy 1.16.0
* pyodbc 4.0.24 vs. pyodbc 4.0.25
* pytz 2018.7 vs. pytz 2018.9
* setuptools 38.5.2 vs. setuptools 28.8.0
I've looked at the following links though I am not sure they will help. Some of the instructions for setting up a proxy in Azure are no longer valid (off by several steps). Recently Azure stopped serving a web app of mine (C#/ASP) when I changed the (totally unrelated Python) setting below.
Application settings->General settings->Python version (from Off to 3.4)
It was a real pain to get it back. I think that I will need a proxy though I would imagine Azure should provide better instructions for this. I am somewhat of an Azure newb though not new enough to start changing things willy nilly!
make Python 3.x Slack (slackclient) use a corporate proxy
Custom Slack Bot cannot connect
https://learn.microsoft.com/en-us/azure/active-directory/manage-apps/application-proxy-configure-connectors-with-proxy-servers
https://learn.microsoft.com/en-us/azure/azure-functions/functions-proxies
import time, logging, os
from slackclient import SlackClient
from datetime import datetime
def main():
#proxies = dict(https="proxy.azure.com:443", http="proxy.azure.com:443")
sc = SlackClient(BOT_TOKEN)
CHANNEL_ID = "some channel id"
logger.debug("Listening to channel '{0}' with id '{1}' for the following actions: ".format(CHANNEL_NAME, CHANNEL_ID))
if sc.rtm_connect():
logger.debug("Connected to Slack!")
while True:
# Read latest messages
# If activity is in CHANNEL_ID do something
else:
logger.debug("Couldn't connect to slack")
On my local machine I get the following (I cut out some of the code):
DEBUG - Listening to channel 'news' with id 'CFDQ3BXYZ' for the following actions:
DEBUG - message_replied
DEBUG - message_deleted
DEBUG - message_changed
DEBUG - Connected to Slack!
However, in Azure, I get the following:
DEBUG - Listening to channel 'news' with id 'CFDQ3BXYZ' for the following actions:
DEBUG - message_replied
DEBUG - message_deleted
DEBUG - message_changed
DEBUG - Couldn't connect to Slack!
The Azure error message is as follows:
01-14-2019 23:17:26, urllib3.connectionpool, DEBUG, Starting new HTTPS connection (1): slack.com:443
01-14-2019 23:17:26, urllib3.connectionpool, DEBUG, https://slack.com:443 "POST /api/rtm.start HTTP/1.1" 200 18349
01-14-2019 23:17:26, slackclient.client, WARNING, Failed RTM connect
Traceback (most recent call last):
File "D:\home\python364x64\lib\site-packages\slackclient\server.py", line 192, in connect_slack_websocket
http_proxy_auth=proxy_auth,
File "D:\home\python364x64\lib\site-packages\websocket\_core.py", line 511, in create_connection
websock.connect(url, **options)
File "D:\home\python364x64\lib\site-packages\websocket\_core.py", line 220, in connect
options.pop('socket', None))
File "D:\home\python364x64\lib\site-packages\websocket\_http.py", line 120, in connect
sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
File "D:\home\python364x64\lib\site-packages\websocket\_http.py", line 164, in _open_socket
sock.setsockopt(*opts)
OSError: [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\home\python364x64\lib\site-packages\slackclient\client.py", line 140, in rtm_connect
self.server.rtm_connect(use_rtm_start=with_team_state, **kwargs)
File "D:\home\python364x64\lib\site-packages\slackclient\server.py", line 159, in rtm_connect
self.connect_slack_websocket(self.ws_url)
File "D:\home\python364x64\lib\site-packages\slackclient\server.py", line 200, in connect_slack_websocket
raise SlackConnectionError(message=str(e))
slackclient.server.SlackConnectionError: [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
01-14-2019 23:17:26, Slack_bot_listener, DEBUG, Couldn't connect to slack
Any help will be greatly appreciated!
It appears that WebJobs are restricted to port 80 only. So there is no way to open up ports, etc. on Azure WebJobs at least at this time (see article/post below). So it appears that a VM or some other route is the way to proceed.
Can I open ports on Azure Websites?
I installed Docker and run the first Cassandra node and used Cqlsh to run some commands and it works fine. I installed python driver and then when i run the command below i get the following error. I saw many stack questions and not much people were able to answer. Please give your ideas. I have been longing for a while to use cassandra but could never come up with a good solution for this problem. Thanks
>>> from cassandra.cluster import Cluster
>>> cluster=Cluster()
>>> keyspace='north'
>>> session=Cluster(['192.168.1.xx']).connect()
Error
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'192.168.1.xx': ConnectionRefusedError(111, "Tried connecting to [('192.168.1.xx', 9042)]. Last error: Connection refused")})
When i tried to replace the Ip address with the cassandra node which i created, 'node1' in my case it gives me this error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "cassandra/cluster.py", line 826, in cassandra.cluster.Cluster.__init__
File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -5] No address associated with hostname
I actually solved this by giving the container Ip address which was inside the docker. I was quite confused which address i should give. But then after running this command.
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id.
I was not aware that i need to specify the container id which had the cluster node. So i was always giving the ip address of the machine.
The IP address you have provided is not valid: 192.168.1.xx.
You need provide the IP address (or valid hostname) of at least one node in your cluster.
I am getting
cx_Oracle.DatabaseError: ORA-12170: TNS:Connect timeout occurred error while connecting oracle from python.
I have installed python 3.7.0 and instantclient_11_2.
Below are the process i am doing,
import cx_Oracle
dsn_tns = cx_Oracle.makedsn( '<ip>', 1521, service_name = '<given service name>')
connection = cx_Oracle.connect('user', 'pwd', dsn_tns)
I have set system veriable PATH where oci.dll is present.
What could be wrong?
Try:
connection = cx_Oracle.connect('user', 'pwd', cx_Oracle.makedsn( '<ip>', '1521',None,'<given service name>'))
Looks the same but works different in my ubuntu server.
Also make sure to put the port between ' '
You should also be able to use the following connect string if the database resides on the same machine:
connection = cx_Oracle.connect('user/pwd#localhost/service_name')
Note that a service_name value is required. You can't use the empty string!
I want to connect oracle db by perl with LDAP, but I got below issue:
No such database (dbase123456)! at /home/cy/scripts/test/lib/DBD/LDAP.pm line 401, line 253.
DBI connect('dbase123456','cy',...) failed: No such database (dbase123456)! at ./test.pl line 28
Can't call method "prepare" on an undefined value at ./test.pl line 29, line 253.
The perl scripst are:
my $query = GetQuery();
my $dbh = DBI->connect("DBI:LDAP:dbase123456",'cy','cy');
my $sth = $dbh->prepare($query);
$sth->execute();
my $rows_ = $sth->fetchall_arrayref();
$sth->finish();
Please someone help me to check the root cause, thanks a lot.
At a guess, you haven't created the configuration file dbase123456.ldb
Take a look at GETTING STARTED from the documentation for the DBD::LDAP driver