How to use the pymysql.install_as_MySQLdb function in PyMySQL

To help you get started, we’ve selected a few PyMySQL examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github maxtepkeev / architect / tests / __init__.py View on Github external
except ImportError:
    from io import StringIO

try:
    import unittest2 as unittest
except ImportError:
    import unittest

try:
    from unittest import mock
except ImportError:
    import mock

try:
    import pymysql
    pymysql.install_as_MySQLdb()
except ImportError:
    pass

from architect.commands import main


@contextlib.contextmanager
def capture():
    out, err, sys.stderr, sys.stdout = sys.stdout, sys.stderr, StringIO(), StringIO()

    try:
        main()
    except SystemExit:
        pass

    sys.stderr.seek(0)
github sqlobject / sqlobject / sqlobject / mysql / mysqlconnection.py View on Github external
def __init__(self, db, user, password='', host='localhost', port=0, **kw):
        drivers = kw.pop('driver', None) or 'mysqldb'
        for driver in drivers.split(','):
            driver = driver.strip()
            if not driver:
                continue
            try:
                if driver.lower() in ('mysqldb', 'pymysql'):
                    if driver.lower() == 'pymysql':
                        import pymysql
                        pymysql.install_as_MySQLdb()
                    import MySQLdb
                    if driver.lower() == 'mysqldb':
                        if MySQLdb.version_info[:3] < (1, 2, 2):
                            raise ValueError(
                                'SQLObject requires MySQLdb 1.2.2 or later')
                    import MySQLdb.constants.CR
                    import MySQLdb.constants.ER
                    self.module = MySQLdb
                    if driver.lower() == 'mysqldb':
                        self.CR_SERVER_GONE_ERROR = \
                            MySQLdb.constants.CR.SERVER_GONE_ERROR
                        self.CR_SERVER_LOST = \
                            MySQLdb.constants.CR.SERVER_LOST
                    else:
                        self.CR_SERVER_GONE_ERROR = \
                            MySQLdb.constants.CR.CR_SERVER_GONE_ERROR
github saltstack / salt / salt / modules / mysql.py View on Github external
from salt.ext import six
# pylint: disable=import-error
from salt.ext.six.moves import range, zip  # pylint: disable=no-name-in-module,redefined-builtin

try:
    # Trying to import MySQLdb
    import MySQLdb
    import MySQLdb.cursors
    import MySQLdb.converters
    from MySQLdb.constants import FIELD_TYPE, FLAG
    from MySQLdb import OperationalError
except ImportError:
    try:
        # MySQLdb import failed, try to import PyMySQL
        import pymysql
        pymysql.install_as_MySQLdb()
        import MySQLdb
        import MySQLdb.cursors
        import MySQLdb.converters
        from MySQLdb.constants import FIELD_TYPE, FLAG
        from MySQLdb import OperationalError
    except ImportError:
        MySQLdb = None

log = logging.getLogger(__name__)

# TODO: this is not used anywhere in the code?
__opts__ = {}

__grants__ = [
    'ALL PRIVILEGES',
    'ALTER',
github HeatDeath / Online-education-platform-Imooc / MxOnline / MxOnline / settings.py View on Github external
# -*- coding:utf-8 -*-
import os
import sys

import pymysql
pymysql.install_as_MySQLdb()

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# 设置 apps 目录
sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
sys.path.insert(0, os.path.join(BASE_DIR, 'extra_apps'))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 's81lk8rsu_5%hzqlh=$aa$tldf=v+7zhvu0r_inqm_82rqhs^w'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
github nict-csl / exist / scripts / insert2db / reputation / plugins_private / sw_ip.py View on Github external
import sys
import os
import configparser
import requests
import pandas as pd
import hashlib
from io import StringIO
from datetime import datetime, timezone

## Django Setup
import django
import pymysql
pymysql.install_as_MySQLdb()
conffile = os.path.join(os.path.dirname(__file__), "../conf/insert2db.conf")
conf = configparser.SafeConfigParser()
conf.read(conffile)
sys.path.append(conf.get('exist', 'syspath'))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'intelligence.settings')
django.setup()
from reputation.models import blacklist
import django.utils.timezone as tzone
from django.db import IntegrityError

## Logger Setup
from logging import getLogger, DEBUG, NullHandler
logger = getLogger(__name__)
logger.addHandler(NullHandler())
logger.setLevel(DEBUG)
logger.propagate = True
github liamculligan / football-data-scraper / scraping.py View on Github external
#Football Analytics

#Scraping Squawka XML pages
#Matches to be scraped must first be manually added using add_matches.py

#Author: Liam Culligan
#Date: January 2017

#Import required packages and functions
import pymysql
pymysql.install_as_MySQLdb() #Install MySQL driver
import MySQLdb as my
import requests
from bs4 import BeautifulSoup
from datetime import datetime
import re
import pandas as pd
import numpy as np
import time
import random

#Define functions
def get_goals_for(score, index):
   return(score[index].strip())
   
def get_goals_against(score, index):
    if index == 0:
github MaayanLab / FAIRshake / manage.py View on Github external
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    try:
        import MySQLdb
    except:
        import pymysql
        pymysql.install_as_MySQLdb()

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "FAIRshake.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)
github r26zhao / django_blog / django_blog / __init__.py View on Github external
from __future__ import absolute_import, unicode_literals
import pymysql
from .celery import app as celery_app
pymysql.install_as_MySQLdb()

__all__ = ['celery_app']
github nict-csl / exist / scripts / insert2db / reputation / plugins / dshield_medium.py View on Github external
import sys
import os
import configparser
import requests
import pandas as pd
import hashlib
from io import StringIO
from datetime import datetime, timezone

## Django Setup
import django
import pymysql
pymysql.install_as_MySQLdb()
conffile = os.path.join(os.path.dirname(__file__), "../../conf/insert2db.conf")
conf = configparser.SafeConfigParser()
conf.read(conffile)
sys.path.append(conf.get('exist', 'syspath'))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'intelligence.settings')
django.setup()
from apps.reputation.models import blacklist
import django.utils.timezone as tzone
from django.db import IntegrityError

## Logger Setup
from logging import getLogger, DEBUG, NullHandler
logger = getLogger(__name__)
logger.addHandler(NullHandler())
logger.setLevel(DEBUG)
logger.propagate = True