Created
July 22, 2023 00:06
-
-
Save borwickatuw/17d4ca34dffe14c2d807aa91ffcb5339 to your computer and use it in GitHub Desktop.
PyMySQL yeet database connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| The below code will connect to a very old and insecure MySQL database. Do not use this for anything important! | |
| No warranty is expressed or implied. | |
| You must use Python ≤3.9 to be able to connect with OpenSSL 1.0 | |
| """ | |
| ctx = ssl.create_default_context() | |
| # https://stackoverflow.com/a/69457639/14068848 | |
| ctx.set_ciphers('ALL:@SECLEVEL=0') | |
| # https://stackoverflow.com/a/33770290/14068848 | |
| ctx.check_hostname = False | |
| ctx.verify_mode = ssl.CERT_NONE | |
| # https://github.com/scrapy/scrapy/issues/5491#issuecomment-1241862323 | |
| ctx.options |= 0x4 # OP_LEGACY_SERVER_CONNECT | |
| return pymysql.connect( | |
| host=config.db_host, | |
| user=config.db_user, | |
| password=config.db_pass, | |
| ssl=ctx, | |
| charset='utf8mb4') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment