Q:

Python request for URL based procedure to automatically download data in bulk from Climate Website (http://www.climate.weather.gc.ca)

I am trying to build a program that downloads a .csv and put it into a pandas dataframe. The instruction suggest i use wget on linux, but it is not working properly when i use 'http.ID={a}/.data'.format(a) to insert different weather stations from a dictionary i made for all the weather station i have to monitor. Here is the read me from government of Canada website.
-----------------------------------------------------------------------

Readme.txt
URL based procedure to automatically download data in bulk from Climate Website
(http://www.climate.weather.gc.ca)
Version: 2016-05-10

ENVIRONMENT AND CLIMATE CHANGE CANADA
To read this file online, please visit:
ftp://client_climate@ftp.tor.ec.gc.ca/Pub/Get_More_Data_Plus_de_donnees/ 
Folder: Get_More_Data_Plus_de_donnees > Readme.txt
Instructions on how to download all weather data for one station from Environment and Climate Change Canada's Climate website: 
A daily updated list of Climate stations in the National Archive, including their Climate ID, Station ID, WMO ID, TC ID, and co-ordinates can be found in the following folder:
Get_More_Data_Plus_de_donnees > Station Inventory EN.csv
Use the following utility to download data: 
wget (GNU / Linux Operating systems)
Cygwin (Windows Operating systems) https://www.cygwin.com
Homebrew (OS X - Apple)  http://brew.sh/
Example to download all available hourly data for Yellowknife A, from 1998 to 2008, in .csv format
Command line:  
for year in `seq 1998 2008`;do for month in `seq 1 12`;do wget --  content-disposition 
"http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID=1706&Year=${year}&Month=${month}&Day=14&timeframe=1&submit= Download+Data" ;done;done

WHERE; 
year = change values in command line (seq 1998 2008)
month = change values in command line (seq 1 12)
format= [csv|xml]: the format output
timeframe = 1: for hourly data 
timeframe = 2: for daily data 
timeframe = 3 for monthly data 
Day: the value of the "day" variable is not used and can be an arbitrary value 
For another station, change the value of the variable stationID
For the data in XML format, change the value of the variable format to xml in the URL. 
For information in French, change Download+Data with 
++T%C3%A9l%C3%A9charger+%0D%0Ades+donn%C3%A9es, also change _e with _f in the url.
For questions or concerns please contact our National Climate Services office at: ec.services.climatiques-climate.services.ec@canada.ca  
-----------------------------------------------------------------------

I originally was using wget to download a csv file from this link. It works without the .format(ID,year).... 
This works:
"http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID=50308&Year=2019&Month=3&Day=14&timeframe=2&submit= Download+Data"

But this doesn't:
"http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID={}&Year={}&Month=3&Day=14&timeframe=2&submit= Download+Data".format(ID,year)

I need to be able to insert different years and station IDs.
This doesn't work, no matter the ID i still get the same weather.
It produces a result, but it isn't the weather station with the ID 50308.
ID = '50308'
year = '2019'
!wget -O Weather.csv"http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID={}&Year={}&Month=3&Day=14&timeframe=2&submit= Download+Data".format(ID,year) 

df = pd.read_csv('Weather.csv',skiprows = 24)

what i am trying to replace the above statement with:
import pandas as pd
import io
import requests

ID = '49088'
year = '2019'

url="http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID={}&Year={}&Month=3&Day=14&timeframe=2&submit= Download+Data".format(ID,year)    
s=requests.get(url).content
c=pd.read_csv(io.StringIO(s.decode('utf-8')))

Here is the error code that it spits out:
ParserError: Error tokenizing data. C error: Expected 2 fields in line 26, saw 27

I would like to be able to make a dictionary for the weather station names and IDs so i can create a function and iterate the dictionary through the function that downloads and puts into a panda data frame. 

A:

Well the requests function fetches the .csv fine, the error is pandas not being able to read the csv properly. The file downloaded starts with lines that contain two fields before an empty line and the data proper. Maybe you don't need the intro converted into panda:
"Station Name","DELTA BURNS BOG"
"Province","BRITISH COLUMBIA"
"Current Station Operator","Environment and Climate Change Canada - Meteorological Service of Canada"
"Latitude","49.13"
"Longitude","-123.00"
"Elevation","3.10"
 .. etc ...

for the first 24 lines then a space and the rest is your data:
"Date/Time","Year","Month","Day","Data Quality","Max Temp (°C)","Max Temp Flag","Min Temp (°C)","Min Temp Flag","Mean Temp (°C)","Mean Temp Flag","Heat Deg Days (°C)","Heat Deg Days Flag","Cool Deg Days (°C)","Cool Deg Days Flag","Total Rain (mm)","Total Rain Flag","Total Snow (cm)","Total Snow Flag","Total Precip (mm)","Total Precip Flag","Snow on Grnd (cm)","Snow on Grnd Flag","Dir of Max Gust (10s deg)","Dir of Max Gust Flag","Spd of Max Gust (km/h)","Spd of Max Gust Flag"
"2019-01-01","2019","01","01","","5.3","","-0.6","","2.4","","15.6","","0.0","","","","","M","0.0","","","","","","",""
"2019-01-02","2019","01","02","","5.2","","0.6","","2.9","","15.1","","0.0","","","","","M","3.4","","","","","","",""
"2019-01-03","2019","01","03","","9.1","","3.4","","6.2","","11.8","","0.0","","","","","M","61.0","","","","","","",""
...

So if you tell pandas to skip the first 25(?) lines you should avoid the parse problems:
h=pd.read_csv(io.StringIO(s.decode('utf-8')), skiprows = 25)

But then again, maybe you actually do need these lines. 
(I don't really know pandas so hopefully wiser words will soon appear).

