
Versuch, die Django 4-App mit PostgreSQL-Datenbank auf Windows Server 2016 mit IIS-Manager 10 und httpPlatformHandler 1.2 zu hosten.
Die App und die Datenbank funktionieren problemlos, wenn sie auf einem VM-Server mit python manage.py runserver
cmd ausgeführt werden. Das Problem tritt beim Zugriffsversuch mit IIS auf. Die Protokolldatei zeigt:
psycopg.OperationalError: connection failed: :1), port 23825 failed: could not receive data from server: Socket is not connected (0x00002749/10057)
could not send SSL negotiation packet: Socket is not connected (0x00002749/10057)
und nachdem ich die DB-Adresse von localhost auf 127.0.0.1 geändert habe, änderte sich der Fehler zu
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\psycopg\connection.py", line 729, in connect
raise ex.with_traceback(None)
django.db.utils.OperationalError: connection failed: could not receive data from server: Socket is not connected (0x00002749/10057)
could not send SSL negotiation packet: Socket is not connected (0x00002749/10057)
und manchmal
psycopg.OperationalError: connection failed: could not receive data from server: Socket is not connected (0x00002749/10057)
could not send SSL negotiation packet: Socket is not connected (0x00002749/10057)
Ich glaube, es gibt im IIS eine Option, die den Verbindungsaufbau verhindert.
Antwort1
Wenn Sie dies noch nicht getan haben, möchten Sie möglicherweise Ihre Datei „pg_hba.conf“ aktualisieren, um Verbindungen vom lokalen Host über IPv4 und IPv6 zuzulassen.
#TYPE DATABASE USER ADDRESS METHOD
host all all 127.0.0.1/32 trust
host all all localhost trust
host all all ::1/128 trust
Weitere Informationen finden Sie hier. https://www.postgresql.org/docs/current/auth-pg-hba-conf.html