import urllib 
import json
import pandas as pd
def monthPageView(page, start, end, project):
    base_url= 'https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/%s/all-access/all-agents/%s/monthly/%s/%s' % (project, page, start, end)
    data = urllib.request.urlopen(base_url)    
    dataJson = json.loads(data.read())['items']
    df = pd.DataFrame(dataJson)[['timestamp', 'views']]
    df = df.rename(columns={'views': '{}_{}'.format(page, 'views')})
    df['timestamp'] = pd.to_datetime(df['timestamp'], format='%Y%m%d%H')
    return df
def monthPagesView(pages, start, end, project):
    result_df = None
    for page in pages:
        df = monthPageView(page, start, end, project)
        if result_df is None:
            result_df = df
        else:
            result_df = pd.merge(result_df, df, on='timestamp')
    return result_df
        
uk_titles_df = pd.read_csv('en_uk_titles.csv')
uk_titles_df['uk_page_title'] = uk_titles_df['uk_page_title'].str.replace(' ', '_')
res = monthPagesView(uk_titles_df['en_page_title'].values,'2017010100','2018040300','ukwiki_p')
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-7-ce0b5385fed6> in <module>()
----> 1 res = monthPagesView(uk_titles_df['en_page_title'].values,'2017010100','2018040300','ukwiki_p')

<ipython-input-3-a7bee9e9fac5> in monthPagesView(pages, start, end, project)
      2     result_df = None
      3     for page in pages:
----> 4         df = monthPageView(page, start, end, project)
      5         if result_df is None:
      6             result_df = df

<ipython-input-2-b7d818496804> in monthPageView(page, start, end, project)
      1 def monthPageView(page, start, end, project):
      2     base_url= 'https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/%s/all-access/all-agents/%s/monthly/%s/%s' % (project, page, start, end)
----> 3     data = urllib.request.urlopen(base_url)
      4     dataJson = json.loads(data.read())['items']
      5     df = pd.DataFrame(dataJson)[['timestamp', 'views']]

/usr/lib/python3.6/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    221     else:
    222         opener = _opener
--> 223     return opener.open(url, data, timeout)
    224 
    225 def install_opener(opener):

/usr/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout)
    530         for processor in self.process_response.get(protocol, []):
    531             meth = getattr(processor, meth_name)
--> 532             response = meth(req, response)
    533 
    534         return response

/usr/lib/python3.6/urllib/request.py in http_response(self, request, response)
    640         if not (200 <= code < 300):
    641             response = self.parent.error(
--> 642                 'http', request, response, code, msg, hdrs)
    643 
    644         return response

/usr/lib/python3.6/urllib/request.py in error(self, proto, *args)
    568         if http_err:
    569             args = (dict, 'default', 'http_error_default') + orig_args
--> 570             return self._call_chain(*args)
    571 
    572 # XXX probably also want an abstract factory that knows when it makes

/usr/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    502         for handler in handlers:
    503             func = getattr(handler, meth_name)
--> 504             result = func(*args)
    505             if result is not None:
    506                 return result

/usr/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    648 class HTTPDefaultErrorHandler(BaseHandler):
    649     def http_error_default(self, req, fp, code, msg, hdrs):
--> 650         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    651 
    652 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 404: Not Found