Advertisement
Guest User

Untitled

a guest
May 10th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3.  
  4.  
  5. import time
  6. import psycopg2
  7. import sys
  8.  
  9. def main():
  10.  
  11. # Get a connection
  12. conn = psycopg2.connect(database='my_db', host='10.10.2.1', port='5433', user='me', password='my_password_that_i_dont_show_here')
  13.  
  14. # conn.cursor will return a cursor object, to perform queries
  15. cursor = conn.cursor()
  16.  
  17. # Execute our query
  18. cursor.execute("select date(created_at), email, firstname, lastname, locale from users where date(created_at) = current_date;")
  19.  
  20. # retrieve the records from the database
  21. records = cursor.fetchall()
  22.  
  23. print(records)
  24.  
  25. if __name__ == "__main__":
  26. main()
  27.  
  28. Traceback (most recent call last):
  29. File "Bureau/script.py", line 29, in <module>
  30. main()
  31. File "Bureau/script.py", line 15, in main
  32. conn = psycopg2.connect(database='my_db', host='10.10.2.1', port='5433', user='me', password='best_password_ever')
  33. File "/usr/local/lib/python3.5/dist-packages/psycopg2/__init__.py", line 164, in connect
  34. conn = _connect(dsn, connection_factory=connection_factory, async=async)
  35. psycopg2.OperationalError: could not connect to server: Connection timed out
  36. Is the server running on host "10.10.2.1" and accepting
  37. TCP/IP connections on port 5433?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement