Question

Janasena on Mon, 02 Apr 2018 09:23:49


I have been trying to connect the postgresql azure to our flask application with psycopg2

DB_CONNECTION = "host='{0}' dbname='{1}' user='{2}' password='{3}' sslmode='{4}' ".format(DB_HOST, APP_NAME,
                                                                                          DB_USER, DB_PASSWORD, 'require')

con = psycopg2.connect(config.DB_CONNECTION)

This is the only code that I have put until now on the service. This throws 

  File "D:\home\site\wwwroot\main.py", line 12, in hello
    con = psycopg2.connect(config.DB_CONNECTION)
  File "D:\home\site\wwwroot\env\lib\site-packages\psycopg2\__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
OperationalError: SSL SYSCALL error: EOF detected

Tried looking out for solutions on the internet with no luck. Please help.

Replies

Mike Ubezzi (Azure) on Mon, 02 Apr 2018 21:35:37


Is this the first time attempting to connect or has this worked successfully previously? I ask this because sometimes that error is thrown when there is a network issue. Can you ping or execute a tracert (traceroute) to the host? Are there any blocking firewall rules in place?

Let me know.

Regards,

Mike

Janasena on Tue, 03 Apr 2018 06:29:10


I am able to connect from my local pgadmin instance with passing root certificate and the password. The same thing when done with the Azure web app with python 2.7 using psycopg2 driver throws me this error. I have tried some variations with passing of root certificate like I did in the pgadmin instance which ended in a failure. So the basic azure web app with  postgres and flask doesn't seem to work in my case. If there are any things that I can do on the web app end to make this work, please do mention.

Janasena on Tue, 03 Apr 2018 07:12:46


Is this the first time attempting to connect or has this worked successfully previously? I ask this because sometimes that error is thrown when there is a network issue. Can you ping or execute a tracert (traceroute) to the host? Are there any blocking firewall rules in place?

Let me know.

Regards,

Mike

So I have gone through with the docs again. As you pointed out the firewall rules, I added the firewall rules to accept all the IP as shown in the docs and it started working. I was able to make a connection and this gave me no errors. Thanks. So I had one more question in mind. As shown in the docs we are allowing all the ips isn't this some kind of security hazard. Is there any way I could add only the web app IP by some way.

Janasena on Tue, 03 Apr 2018 09:00:38


Hi Mike,

Can you point me to tutorials on how to use celery as web worker in azure environment. I have gone through the web jobs but they seem to have a limited scope and run outside the scope of web application. We are looking for something that works like heroku instance where we get to define what to run as worker and what to run as a web instance.

Mike Ubezzi (Azure) on Thu, 19 Apr 2018 20:40:17


Apologies for the delay Janasena but, this Stack Overflow post may help you with running Celery.

Use Windows Azure Worker Role with Celery

Regards,

Mike