How to Solve NameError: name 'connection' is not defined -- psycopg2

Solution: Import the 'connection' module

To Solve the error, add the following line to the top of your code.

from psycopg2._psycopg import connection

 

For more information:
Python psycopg2 connection