import pymysql
from sqlalchemy import create_engine
import os
import pandas as pd
conn = pymysql.connect(
    host=os.environ['MYSQL_HOST'],
    user=os.environ['MYSQL_USERNAME'],
    password=os.environ['MYSQL_PASSWORD'],
    database='enwiki_p',
    charset='utf8'
)
with conn.cursor() as cur:
    cur.execute('use enwiki_p')
    cur.execute("""SELECT * from user """)
    allu = cur.fetchall()
    print(allu)
    
    #cur.execute("""SELECT * from user where user_name = 'Jtmorgan'""")
    #jtmorgan = cur.fetchall()
    #cur.execute("""SELECT * from user where user_name = 'HostBot'""")
    #hostbot = cur.fetchall()
    #print(jtmorgan)
    #print(hostbot)
type(allu)
print(len(allu))
names = pd.Series()
  File "<ipython-input-46-8fb6942eced2>", line 1
    global names = pd.Series()
                 ^
SyntaxError: invalid syntax
def getUserNames(tupleu):
    print(tupleu)
    t = 0
    while t < len(tupleu):
        print(t)
        username = allu[t][1]
        #decode byte string to UTF to make it compatible with most other strings you'll be using
        uname = username.decode("utf8")
        unames = names.append(pd.Series([uname]))
        print(unames.head())   
        t = t+1
    return unames    
unames = getUserNames(allu)
((1, b'Damian Yerrick', b'', None, None, None, None, None, None, None, None, None, b'20010929004320', None, 14784, None), (2, b'AxelBoldt', b'', None, None, None, None, None, None, None, None, None, b'20010726145009', None, 41587, None), (3, b'Tobias Hoevekamp', b'', None, None, None, None, None, None, None, None, None, b'20010326202105', None, 1903, None), (4, b'Magnus Manske', b'', None, None, None, None, None, None, None, None, None, b'20010728082538', None, 24229, None), (5, b'Hoevekam~enwiki', b'', None, None, None, None, None, None, None, None, None, b'20030709192137', None, 3, None), (6, b'Paul Drye', b'', None, None, None, None, None, None, None, None, None, b'20010919131128', None, 1135, None), (7, b'Joao', b'', None, None, None, None, None, None, None, None, None, b'20010826124114', None, 266, None), (8, b'TwoOneTwo', b'', None, None, None, None, None, None, None, None, None, b'20010909202356', None, 2135, None), (9, b'Chenyu', b'', None, None, None, None, None, None, None, None, None, b'20011119003449', None, 166, None), (10, b'Tbc~enwiki', b'', None, None, None, None, None, None, None, None, None, b'20010803144007', None, 125, None))
0
0    Damian Yerrick
dtype: object
1
0    AxelBoldt
dtype: object
2
0    Tobias Hoevekamp
dtype: object
3
0    Magnus Manske
dtype: object
4
0    Hoevekam~enwiki
dtype: object
5
0    Paul Drye
dtype: object
6
0    Joao
dtype: object
7
0    TwoOneTwo
dtype: object
8
0    Chenyu
dtype: object
9
0    Tbc~enwiki
dtype: object
names.head()
unames.to_csv("enwiki_users.csv")
 
 
 
 
 
################################## My queries
host=os.environ['MYSQL_HOST']
host.
user=os.environ['MYSQL_USERNAME']
password=os.environ['MYSQL_PASSWORD']
database='enwiki_p'
engine= "mysql+pymysql://"+user+":"+password+host+"/"+database
engine = create_engine(engine)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-21-010572cd7d08> in <module>()
      1 engine= "mysql+pymysql://"+user+":"+password+host+"/"+database
----> 2 engine = create_engine(engine)

/srv/paws/lib/python3.6/site-packages/sqlalchemy/engine/__init__.py in create_engine(*args, **kwargs)
    422     strategy = kwargs.pop('strategy', default_strategy)
    423     strategy = strategies.strategies[strategy]
--> 424     return strategy.create(*args, **kwargs)
    425 
    426 

/srv/paws/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py in create(self, name_or_url, **kwargs)
     48     def create(self, name_or_url, **kwargs):
     49         # create url.URL object
---> 50         u = url.make_url(name_or_url)
     51 
     52         plugins = u._instantiate_plugins(kwargs)

/srv/paws/lib/python3.6/site-packages/sqlalchemy/engine/url.py in make_url(name_or_url)
    209 
    210     if isinstance(name_or_url, util.string_types):
--> 211         return _parse_rfc1738_args(name_or_url)
    212     else:
    213         return name_or_url

/srv/paws/lib/python3.6/site-packages/sqlalchemy/engine/url.py in _parse_rfc1738_args(name)
    265         components['host'] = ipv4host or ipv6host
    266         name = components.pop('name')
--> 267         return URL(name, **components)
    268     else:
    269         raise exc.ArgumentError(

/srv/paws/lib/python3.6/site-packages/sqlalchemy/engine/url.py in __init__(self, drivername, username, password, host, port, database, query)
     58         self.host = host
     59         if port is not None:
---> 60             self.port = int(port)
     61         else:
     62             self.port = None

ValueError: invalid literal for int() with base 10: 'ec65c6ecb3bbe2aa5e08524b74553e7311da619aede7754fa91c966599a9f97b10.110.98.159'
result = pd.read_sql_query("""SELECT * from user where user_name = 'Jtmorgan'""", engine)
result.head()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-22-9ce9c88da108> in <module>()
----> 1 result = pd.read_sql_query("""SELECT * from user where user_name = 'Jtmorgan'""", engine)
      2 result.head()

/srv/paws/lib/python3.6/site-packages/pandas/io/sql.py in read_sql_query(sql, con, index_col, coerce_float, params, parse_dates, chunksize)
    309 
    310     """
--> 311     pandas_sql = pandasSQL_builder(con)
    312     return pandas_sql.read_query(
    313         sql, index_col=index_col, params=params, coerce_float=coerce_float,

/srv/paws/lib/python3.6/site-packages/pandas/io/sql.py in pandasSQL_builder(con, schema, meta, is_cursor)
    504     # When support for DBAPI connections is removed,
    505     # is_cursor should not be necessary.
--> 506     con = _engine_builder(con)
    507     if _is_sqlalchemy_connectable(con):
    508         return SQLDatabase(con, schema=schema, meta=meta)

/srv/paws/lib/python3.6/site-packages/pandas/io/sql.py in _engine_builder(con)
    490             _SQLALCHEMY_INSTALLED = False
    491         else:
--> 492             con = sqlalchemy.create_engine(con)
    493             return con
    494 

/srv/paws/lib/python3.6/site-packages/sqlalchemy/engine/__init__.py in create_engine(*args, **kwargs)
    422     strategy = kwargs.pop('strategy', default_strategy)
    423     strategy = strategies.strategies[strategy]
--> 424     return strategy.create(*args, **kwargs)
    425 
    426 

/srv/paws/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py in create(self, name_or_url, **kwargs)
     48     def create(self, name_or_url, **kwargs):
     49         # create url.URL object
---> 50         u = url.make_url(name_or_url)
     51 
     52         plugins = u._instantiate_plugins(kwargs)

/srv/paws/lib/python3.6/site-packages/sqlalchemy/engine/url.py in make_url(name_or_url)
    209 
    210     if isinstance(name_or_url, util.string_types):
--> 211         return _parse_rfc1738_args(name_or_url)
    212     else:
    213         return name_or_url

/srv/paws/lib/python3.6/site-packages/sqlalchemy/engine/url.py in _parse_rfc1738_args(name)
    265         components['host'] = ipv4host or ipv6host
    266         name = components.pop('name')
--> 267         return URL(name, **components)
    268     else:
    269         raise exc.ArgumentError(

/srv/paws/lib/python3.6/site-packages/sqlalchemy/engine/url.py in __init__(self, drivername, username, password, host, port, database, query)
     58         self.host = host
     59         if port is not None:
---> 60             self.port = int(port)
     61         else:
     62             self.port = None

ValueError: invalid literal for int() with base 10: 'ec65c6ecb3bbe2aa5e08524b74553e7311da619aede7754fa91c966599a9f97b10.110.98.159'
 
conn = pymysql.connect(
    host=os.environ['MYSQL_HOST'],
    user=os.environ['MYSQL_USERNAME'],
    password=os.environ['MYSQL_PASSWORD'],
    database='enwiki_p',
    charset='utf8'
)
with conn.cursor() as cur:
    cur.execute('use enwiki_p')
    cur.execute("""SELECT DISTINCT user_name from user LIMIT 10""")
    allusers = cur.fetchall()
   
    print(allusers)
((b'!',), (b'! !',), (b'! ! !',), (b'! ! ! !',), (b'! ! ! ! !',), (b'! ! ! ! ! !',), (b'! ! ! ! ! ! !',), (b'! ! ! ! ! ! ! !',), (b'! ! ! ! ! ! ! ! !',), (b'! ! ! ! ! ! ! ! ! !',))