Skip to content

Commit c1277f4

Browse files
committed
Add ssl context for database connection
For some reason asyncpg doesn't connect with just db URI, see: MagicStack/asyncpg#238
1 parent 890bb88 commit c1277f4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

storing.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import json
1010
import logging
1111
import os
12+
import ssl
1213
from datetime import datetime
1314

1415
import asyncpg
@@ -19,7 +20,6 @@
1920
DATABASE_URL = os.environ["DATABASE_URI"]
2021
VALID_FOR_DAYS = 30
2122

22-
2323
logging.basicConfig(
2424
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
2525
)
@@ -41,7 +41,10 @@ def process(keyphrase: str) -> list:
4141
)
4242
artist = keyphrase.lower()
4343
today = datetime.now()
44-
conn = await asyncpg.connect(dsn=DATABASE_URL)
44+
ctx = ssl.create_default_context()
45+
ctx.check_hostname = False
46+
ctx.verify_mode = ssl.CERT_NONE
47+
conn = await asyncpg.connect(dsn=DATABASE_URL, ssl=ctx)
4548
record = await conn.fetch(f"SELECT * FROM top WHERE artist = '{artist}'")
4649
if (
4750
record

0 commit comments

Comments
 (0)