# from https://pythonhosted.org/mwreverts/db.html#mwreverts.db.check :
import os
import mwdb
import mwreverts.api
# added (obviously missing from https://pythonhosted.org/mwreverts/db.html#mwreverts.db.check )
import mwreverts.db
import pymysql

# amended per https://paws-public.wmflabs.org/paws-public/User:YuviPanda/replicahelper.ipynb :
host = os.environ['MYSQL_HOST']
user = os.environ['MYSQL_USERNAME']
password = os.environ['MYSQL_PASSWORD']
connection_string = 'mysql+pymysql://{user}:{password}@{host}/enwiki_p?charset=utf8mb4'.format(
    user=user,
    password=password,
    host=host
)
schema = mwdb.Schema(connection_string)

def print_revert(revert):
    if revert is None:
        print(None)
    else:
        print(revert.reverting['rev_id'],
              [r['rev_id'] for r in revert.reverteds],
              revert.reverted_to['rev_id'])

reverting, reverted, reverted_to = mwreverts.db.check(schema, 679778587)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-3b87028513a7> in <module>()
     16     host=host
     17 )
---> 18 schema = mwdb.Schema(connection_string)
     19 
     20 def print_revert(revert):

/srv/paws/lib/python3.4/site-packages/mwdb/schema.py in __init__(self, engine_or_url, only_tables, *args, **kwargs)
    112 
    113         self.meta = MetaData(bind=self.engine)
--> 114         self.meta.reflect(views=True, only=only_tables or self.ONLY_TABLES)
    115         self.public_replica = 'revision_userindex' in self.meta
    116         """

/srv/paws/lib/python3.4/site-packages/sqlalchemy/sql/schema.py in reflect(self, bind, schema, views, only, extend_existing, autoload_replace, **dialect_kwargs)
   3783 
   3784             available = util.OrderedSet(
-> 3785                 bind.engine.table_names(schema, connection=conn))
   3786             if views:
   3787                 available.update(

/srv/paws/lib/python3.4/site-packages/sqlalchemy/engine/base.py in table_names(self, schema, connection)
   2117             if not schema:
   2118                 schema = self.dialect.default_schema_name
-> 2119             return self.dialect.get_table_names(conn, schema)
   2120 
   2121     def has_table(self, table_name, schema=None):

<string> in get_table_names(self, connection, schema, **kw)

/srv/paws/lib/python3.4/site-packages/sqlalchemy/engine/reflection.py in cache(fn, self, con, *args, **kw)
     40     info_cache = kw.get('info_cache', None)
     41     if info_cache is None:
---> 42         return fn(self, con, *args, **kw)
     43     key = (
     44         fn.__name__,

/srv/paws/lib/python3.4/site-packages/sqlalchemy/dialects/mysql/base.py in get_table_names(self, connection, schema, **kw)
   1711             rp = connection.execute(
   1712                 "SHOW FULL TABLES FROM %s" %
-> 1713                 self.identifier_preparer.quote_identifier(current_schema))
   1714 
   1715             return [row[0]

/srv/paws/lib/python3.4/site-packages/sqlalchemy/sql/compiler.py in quote_identifier(self, value)
   2873 
   2874         return self.initial_quote + \
-> 2875             self._escape_identifier(value) + \
   2876             self.final_quote
   2877 

/srv/paws/lib/python3.4/site-packages/sqlalchemy/dialects/mysql/mysqldb.py in _escape_identifier(self, value)
     76 
     77     def _escape_identifier(self, value):
---> 78         value = value.replace(self.escape_quote, self.escape_to_quote)
     79         return value.replace("%", "%%")
     80 

AttributeError: 'NoneType' object has no attribute 'replace'
import pymysql
connection_string = 'mysql://{user}:{password}@{host}/enwiki_p?charset=utf8mb4'.format(
    user=user,
    password=password,
    host=host
)
pymysql.connect(connection_string)
---------------------------------------------------------------------------
UnicodeError                              Traceback (most recent call last)
/srv/paws/lib/python3.4/encodings/idna.py in encode(self, input, errors)
    164                 if not (0 < len(label) < 64):
--> 165                     raise UnicodeError("label empty or too long")
    166             if len(labels[-1]) >= 64:

UnicodeError: label empty or too long

The above exception was the direct cause of the following exception:

UnicodeError                              Traceback (most recent call last)
<ipython-input-7-421497d3b92c> in <module>()
      5     host=host
      6 )
----> 7 pymysql.connect(connection_string)

/srv/paws/lib/python3.4/site-packages/pymysql/__init__.py in Connect(*args, **kwargs)
     88     """
     89     from .connections import Connection
---> 90     return Connection(*args, **kwargs)
     91 
     92 from . import connections as _orig_conn

/srv/paws/lib/python3.4/site-packages/pymysql/connections.py in __init__(self, host, user, password, database, port, unix_socket, charset, sql_mode, read_default_file, conv, use_unicode, client_flag, cursorclass, init_command, connect_timeout, ssl, read_default_group, compress, named_pipe, no_delay, autocommit, db, passwd, local_infile, max_allowed_packet, defer_connect, auth_plugin_map, read_timeout, write_timeout, bind_address)
    697             self._sock = None
    698         else:
--> 699             self.connect()
    700 
    701     def _create_ssl_ctx(self, sslp):

/srv/paws/lib/python3.4/site-packages/pymysql/connections.py in connect(self, sock)
    910                             sock = socket.create_connection(
    911                                 (self.host, self.port), self.connect_timeout,
--> 912                                 **kwargs)
    913                             break
    914                         except (OSError, IOError) as e:

/usr/lib/python3.4/socket.py in create_connection(address, timeout, source_address)
    489     host, port = address
    490     err = None
--> 491     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    492         af, socktype, proto, canonname, sa = res
    493         sock = None

/usr/lib/python3.4/socket.py in getaddrinfo(host, port, family, type, proto, flags)
    528     # and socket type values to enum constants.
    529     addrlist = []
--> 530     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    531         af, socktype, proto, canonname, sa = res
    532         addrlist.append((_intenum_converter(af, AddressFamily),

UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long)