Python: unable connect with database
Question: Python 3.4 with psycopg2

I used [this
guide](https://wiki.postgresql.org/wiki/Using_psycopg2_with_PostgreSQL) to set
up a basic `psycopg2` connection like so:

    
    
    #!/usr/bin/python
    import psycopg2
    import sys
    import pprint
    
    def main():
        conn_string = "dbname='CIBTST' host='XX.XX.XXX.XX' port='XXXX' user='XXXXX' password='XXXX'"
        conn = psycopg2.connect(conn_string)
        cursor = conn.cursor()
        cursor.execute("My_select")
        records = cursor.fetchall()
        pprint.pprint(records)
    if __name__ == "__main__":
        main()
    

I get this traceback:

    
    
    Traceback (most recent call last):
    File "C:\Users\pi24926\Desktop\Python\doSMS.py", line 14, in <module>
    main()
    File "C:\Users\pi24926\Desktop\Python\doSMS.py", line 8, in main
    conn = psycopg2.connect(conn_string)
    File "C:\Python34\lib\site-packages\psycopg2\__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
    psycopg2.OperationalError
    

When I try the same select statement in another client (Toad) it seems to
operate correctly. Any suggestions will be great. Thank you!

EDIT: The source of problem is: PORT. If I run:

    
    
    #!/usr/bin/python
    import psycopg2
    import sys
    import pprint
    
    def main():
        conn_string = "dbname='CIBTST' host='XX.XX.XXX.XX' user='XXXXX' password='XXXX'"
        conn = psycopg2.connect(conn_string)
        cursor = conn.cursor()
        cursor.execute("My_select")
        records = cursor.fetchall()
        pprint.pprint(records)
    if __name__ == "__main__":
        main()
    

Then I get:

    
    
    Traceback (most recent call last):
    File "C:\Users\pi24926\Desktop\Python\doSMS.py", line 14, in <module>
    main()
    File "C:\Users\pi24926\Desktop\Python\doSMS.py", line 8, in main
    conn = psycopg2.connect(conn_string)
    File "C:\Python34\lib\site-packages\psycopg2\__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
    psycopg2.OperationalError: could not connect to server: Connection timed out  (0x0000274C/10060)
    Is the server running on host "XXXXXXX" and accepting
    TCP/IP connections on port 5432?
    

I can only connect under port 1522 for some reason. Any ideas?


Answer: The problem was with database...

It is an Oracle, so i should use cx_Oracle instead of psycopg2.

