-
Notifications
You must be signed in to change notification settings - Fork 419
SSL Certificate Verify Failed #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@amsb Nope. It is already installed. |
@modelmat Are you passing the correct SSL context? Your system is missing the necessary root and/or intermediate certs to verify the server certificate. If the server is not using a self-signed cert, then the following should work in most cases: await asyncpg.connect(..., ssl=ssl.create_default_context(capath=certifi.where())) |
I still get the same error. It works with pyscopg2, but not with asyncpg, os not sure why |
@modelmat @elprans I had the same problem. If you happen to be using AWS RDS, it looks like you need to use their root certificate (e.g. when connecting via We haven't encountered this problem when using After banging my head for a while, I was able to successfully connect by appending the contents of AWS' root certificate bundle to the CA bundle in my environment (docker/ubuntu 14.04, postgres 9.5) |
@zharben I do happen to be using Amazon AWS. However, adding the certificate file in (Windows), in Internet Options > Content > Certificates > Import, then importing the |
Is there a way to make |
The whole point of SSL is that it is verified.
|
So like this?
Because that doesn't seem to work. |
Well, that's weird. I'll try to reproduce. Meanwhile you can disable the certificate verification like this: ssl_object = ...
ssl_object.check_hostname = False
ssl_object.verify_mode = ssl.CERT_NONE
# connect... |
Those made it work. I can send the file if you want |
Duh. Replace |
That doesn't work. |
Works for me. Double-check your CA file and that the intermediate cert matches your region. |
FYI, this didn't work for me either, despite following the steps carefully. |
Doesn't work for me either. I use the version 0.15.0 if |
@savvopoulos @avli Are you on RDS? |
Yes, via heroku. |
OK, so I went and created a test RDS instance to test. The following works perfectly for me: import asyncio
import asyncpg
import os.path
import ssl
async def aws_ssl():
ctx = ssl.create_default_context(
cafile=os.path.join(os.path.dirname(__file__), 'rds-combined-ca-bundle.pem'))
pool = await asyncpg.create_pool(
host='asyncpg-test.cpa3bgqi3hfw.us-east-1.rds.amazonaws.com',
user='postgres',
database='test',
password='***',
ssl=ctx
)
async with pool.acquire() as conn:
try:
print(await conn.fetchval('SELECT 1'))
finally:
pass
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(aws_ssl()) Where |
Same for me – RDS via Heroku. @elprans Thank you for the proposed solution. I'll check it out and let you know. |
I just tried this, it doesn't like it either - I don't suppose using the entire Traceback (most recent call last):
File "C:\Users\Modelmat\Desktop\db.py", line 23, in <module>
loop.run_until_complete(aws_ssl())
File "D:\Program Files\Python3\lib\asyncio\base_events.py", line 467, in run_until_complete
return future.result()
File "C:\Users\Modelmat\Desktop\db.py", line 12, in aws_ssl
ssl=ctx
File "D:\Program Files\Python3\lib\site-packages\asyncpg\pool.py", line 356, in _async__init__
await first_ch.connect()
File "D:\Program Files\Python3\lib\site-packages\asyncpg\pool.py", line 126, in connect
**self._connect_kwargs)
File "D:\Program Files\Python3\lib\site-packages\asyncpg\connection.py", line 1512, in connect
max_cacheable_statement_size=max_cacheable_statement_size)
File "D:\Program Files\Python3\lib\site-packages\asyncpg\connect_utils.py", line 314, in _connect
raise last_error
File "D:\Program Files\Python3\lib\site-packages\asyncpg\connect_utils.py", line 306, in _connect
connection_class=connection_class)
File "D:\Program Files\Python3\lib\site-packages\asyncpg\connect_utils.py", line 276, in _connect_addr
connector, timeout=timeout, loop=loop)
File "D:\Program Files\Python3\lib\asyncio\tasks.py", line 358, in wait_for
return fut.result()
File "D:\Program Files\Python3\lib\site-packages\asyncpg\connect_utils.py", line 345, in _create_ssl_connection
server_hostname=host)
File "D:\Program Files\Python3\lib\asyncio\base_events.py", line 803, in create_connection
sock, protocol_factory, ssl, server_hostname)
File "D:\Program Files\Python3\lib\asyncio\base_events.py", line 829, in _create_connection_transport
yield from waiter
File "D:\Program Files\Python3\lib\asyncio\sslproto.py", line 501, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "D:\Program Files\Python3\lib\asyncio\sslproto.py", line 201, in feed_ssldata
self._sslobj.do_handshake()
File "D:\Program Files\Python3\lib\ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777) |
I have tried it too – got the same error as in the comment above. |
Bump? |
I've noticed this problem recently as well. A few things I'll add:
I've used Node on Heroku before, with this pg package, and I always used |
Thanks, guys, here is what eventually works for me:
|
I'm sorry if this is a naive question, but what is the point of a private key (=pem), if it's available online? |
PEM is an encoding format. These are all certificates in pem format. |
Had the same problem trying to connect to aiven.io pg instance. After downloading the certificate from aiven project, this code worked. Don't forget to |
@imbolc I think there's little point in actually using the certificate if you disable verification ( |
Thanks for this #238 (comment) works for me ;) |
Thought the same thing. You are right. |
Work too |
For some reason asyncpg doesn't connect with just db URI, see: MagicStack/asyncpg#238
…ncpg#238 (comment) . PEP8 tabs in decorator
@elprans With the example RDS setup provided I actually couldn't connect to my RDS instance - perhaps due to my org's SSL setup. However, I can connect with a psycopg based driver using my DSN. The key difference for me, I think, is that pyscopg supports |
|
@elprans I managed to get it to work but only by disabling the hostname check (not the verify_mode). I guess this is because sslmode I guess from a user perspective it's somewhat unclear that the sslmode connection param is supported by asyncpg but it is somewhat overriden by the SSL context. Thanks for your help also, this thread was very useful to me :). |
Good point. I'll add a clarification. |
Asyncpg doesn't work with Connecting with psql:
Asyncpg connect script:
Error:
Tried the same with sqlalchemy with psycopg2 driver. It works great.
|
the issue with a local PostgreSQL install? Yes, Heroku.:
I was getting the same issue as #119 . I enabled the ssl=True in the
await asyncpg.create_pool(self.dsn, ssl=True)
- and the same occurs with connect.So then I used the SSL keyword param, and got
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
.The text was updated successfully, but these errors were encountered: